One of the most frustrating things to happen (all the time) when you're in the Stata groove is to get that error message, "no room to add more observations." Yes, you can usually add more more memory (use the 'set memory' command), and if you can't, you can always buy a new computer with more memory. But insufficient memory issues often come up when you have many dummy variables in your model. I used to make them using the tabulate command:
tabulate var, gen(newstub)
There's a much better way! You don't actually need to create those variables! Much better to just add "i." to the beginning of your variable within the regression command:
regress y i.var
Done. You can even specify the base and test for equality of different dummy coefficients!
You can use a similar trick for interaction variables. Instead of creating several interaction variables,
generate femaleXgroup2=female*group2
generate femaleXgroup3=female*group3
just use this regression command:
regress y i.sex i.group sex#group
Actually, even better to do this:
regress y sex##group
I would say that one of the most-often made coding errors I see is to forget to include one of the non-interacted variables in regression models with interaction terms. By using the ## trick, you don't need to worry about it! Oh, if one of the variables is continuous, you need to tell Stata this by putting "c." before the variable. For example,
regress y i.sex age sex#c.age
or regress y sex##c.age
More details here. Or for quick reference, look at the this cheat sheet.
No comments:
Post a Comment