Stata syntax surprise
Here are two bits of syntax that have truly facilitated my life.
When faced with a load of survey variables to clean or recode or regress, the long-winded way is to do them all individually.
e.g.
regress var1 iv1 iv2 iv3
regress var2 iv1 iv2 iv3
regress var3 iv1 iv2 iv3
Needless to say, it stops being fun after about var5.
So the solution is to set up a little macro. Say there are 7 variables we want to regress using the same regression model.
forval x=1/7 {
regress var`x' iv1 iv2 iv3
}
It's so beautiful!
But wait! What if your variable doesn't have a number? What if it's vara varb varc vard etc?
There is another beautiful loop.
foreach x of new `c(alpha)'{
dis "x'"
regress var`x' iv1 iv2 iv3
}
This loop will cycle through the aphabet. If you have variables from a to k, it will stop at k.
And these two little loops have revolutionised my syntax.
They can be used with anything!
My next mission: to find out how they can be combined.
---
Internet credits for the alpha loop: http://www.poliscijobrumors.com/topic.php?id=24913
Other useful stata sites and things:
http://www.cpc.unc.edu/research/tools/data_analysis/statatutorial (love the syntax walkthroughs)
http://www.ats.ucla.edu/stat/stata/ (love the annotated outputs)
Publication-ready tables: try tabout outreg/outreg2 and estout
http://www.ianwatson.com.au/stata/tabout_tutorial.pdf
http://econpapers.repec.org/software/bocbocode/s456416.htm
http://repec.org/bocode/e/estout/
Add a comment
You are not allowed to comment on this entry as it has restricted commenting permissions.