Programming notes

November 12, 2009 at 3:33 pm 2 comments

| Gabriel |

I gave a lecture to my grad stats class today on Stata programming. Regular readers of the blog will have heard most of this before but I thought it would help to have it consolidated and let more recent readers catch up.

Here’s my lecture notes. [Updated link 10/14/2010]

Entry filed under: Uncategorized. Tags: , , .

Science (esp. econ) made fun A few stats pedagogy notes

2 Comments

  • 1. Matissa  |  November 13, 2009 at 11:28 am

    Thanks, a useful overview. I think you have one typo, though, at the beginning of your section about loops. You have the line that starts::

    foreach var in “PEX4A PEX4B …..

    I don’t think you want the quotes in there, in other words, you want:

    foreach var in PEX4A PEX4B …..

    The quotes tell stata to keep the items together even though there is a space separating them. So, the way it was written, the loop would only occur once with the macro `var’ holding the entire contents inside the quotes. The use of quotes can be helpful when you do have a list of items that contain spaces, but in this case it’s going to get you into trouble.

    To show what I mean, here are a number of commands to run interactively to get a sense of what is going on:

    set trace on
    sysuse auto
    foreach var in “price mpg” {
    gen `var’100=`var’/100
    }
    foreach var in price mpg {
    gen `var’100=`var’/100
    }

    • 2. gabrielrossman  |  November 13, 2009 at 1:05 pm

      thanks, i’ve fixed the pdf.
      i actually knew this in principle but screwed it up in practice. the reason is that in my actual SPPA do-file I first define a global (which does take quotes) then use the global to seed the loop. i tried to simplify the loop for pedagogical purposes and in so doing introduced the problem you identified.
      thanks again


The Culture Geeks


%d bloggers like this: