Saturday, December 21, 2013

Combating projection bias

One manifestation of projection bias is where you think that your views won't change with time. For example, young people often think they will never want to be married or have children. I think a neat idea for a website would be to summarize from long-running surveys to see which opinions or beliefs change with age and which do not. You could even break out the data by subgroup so that someone could see, for example that "of the people with similar education and income levels who held my view, X% changed their mind". This might help when thinking about long-term commitments such as living location, jobs, and partners.

Wednesday, September 11, 2013

Automated Statistical Reports in MS Office

I prefer LyX to Microsoft Office when writing academic works, but sometimes MS Word/Powerpoint is necessary. My one requirement for the workflow is that manual fiddling isn't required. This is a bit challenging because Office products can't show PS/PDF material inline. You can include an EPS as a graphic which can print OK (if you print to a PDF or have a PS printer), which is fine for Word, but will only show an unavoidably ugly "preview" inline which doesn't work for PowerPoint. For presentations, you should output to a raster format (like PNG) or for tables you can possibly output to EMF.

Generating EPS/PNG files from graphics is built into most stats software (R, Stata), so the only hard part is converting tables. I'll assume you can generate these a tex and start there (so as to minimize differences between Office and Latex generated reports). Scripts below were tested on Windows 7 with Cygwin and I had placed the programs in step four in my path.
  1. Export a table to mytable.frag.tex.
  2. Wrap that tex fragment in a minimal "standalone" document.
    • >echo \documentclass[varwidth=true, border=10pt]{standalone} > mytable.tex
    • >echo \begin{document} >> mytable.tex
    • >cat mytable.frag.tex  >> mytable.tex
    • >echo \end{document} >> mytable.tex
  3. Make your table into a "standalone" PDF (the PDF will be just the size of the table). Your TeX distribution will automatically download the 'standalone' package.
    • >pdflatex mytable.tex
  4. Convert the PDF to the output required.
    • >pdftops -eps mytable.pdf mytable.eps
      • Could also do this in Ghostscript like below.
    • >pstoedit -f emf mytable.pdf mytable.emf
      • This will change the fonts on you. If you have Greek letters this conversion might fail in which case you need to add -adt which turns letters into polygons (not perfect but OK). You can also convert with Adobe Illustrator which will also do font conversion.
    • >gswin64c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pnggray -r600 -sOutputFile=mytable.png mytable.pdf
There are two options for inserting. The first is the easiest uses absolute paths for images so won't work well with sharing the files among other users (e.g. in Dropbox) or moving the project folder.

  • Use normal image insertion but use the dropdown next to "Insert" and select "Insert and Link". Some VBA scripts are available that will convert the absolute path to relative paths (e.g. here).
  • Insert pictures using field codes. Insert -> Quick Parts -> IncludePicture. Then put in a relative path like pics\pic1.png and select "Data not stored with document" (and you probably want to check resizing both horizontally and vertically). If you want to convert to pictures (if you send it out), then remove the "Data not ..." by removing "\d" from the field code, and make a formatting edit (like going to Format Picture and then changing the Layout wrapping style).

Now when the linked files are updated by programs, they will be updated in Office. If the document is open then select an image (or using select all) and press F9.

Edit 2016-01-22: Expanded part about relative paths to images.

Also note that emfs might not display correctly on Mac Powerpoints (same for MathType equations). You can print pptxs to pdfs but then you will lose any animations.

Thursday, September 05, 2013

Modifying Stata library routines

I was recently not understanding why some error messages were being generated by mata's optimize(). I found that it was quite easy to modify the routines to include some debugging print-outs. Broadly we want to create modified routines that mask the existing ones. Here's the basic steps:

  1. Find the mata file (in my case deriv.mata) in the Stata folder, copied it to your own directory, and make changes. 
  2. Turn it into a personal library. See the basic template at -help mata_mlib-.
  3. Have the personal library called instead of the builtin routines. The -mata mlib index- command from the previous step outputted the order in which the libraries are searched for a function.

Enjoy your modified version. When you're all done you can use -mata mlib index- again to get the default ordering.

Wednesday, June 26, 2013

Strategic voting and Oxford-style debates

In determining which side wins a debate, one variant of  Oxford-style debates has people vote about a proposition before and after hearing the debate. The side that sways the most voters towards theirs wins. For example, if an audience votes initially that they are (60% For, 20% Against, 20% Undecided) and afterward they are (65% For, 30% Against, 5% Undecided) then the Against side wins (they change 10% toward their side while the other only swayed 5%). This system, though, incentivizes dishonesty in the first round. If I believe I am unlikely to change my mind during the debate, I should vote opposite my current view in the initial vote.

To see if strategic voting is a problem, one could take a debate's audience and have half of the people's votes be noted but not counted towards the winner. If the counts of the two groups differ, then something might be going on.

The harder question is how do you incentivize truth telling for those that switch.
Edit: One way maybe would be to just have a vote at the end but have a prediction market (for the final vote) be going throughout the debate. The winner of the debate is the one that moved the market price the most.