Raj Arunachalam
unread,May 23, 2013, 3:45:01 PM5/23/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to income-dynam...@googlegroups.com
Hi all,
Great work today! Here are some Stata tips that came to me as you were giving your Stata presentations. Not all are based on the code you used, but I hope they will be helpful. Cheers!
--raj
1. Avoid putting spaces in directory names and file names. Use underscore instead. This avoids having to deal with quotes and even sometimes what Stata calls compound double quotes, which can be very confusing.
2a. -, replace- is handy, when saving datasets, tables, graphs.
2b. However, careful when using in combination with -tempfile-. -tempfile- creates a local telling Stata files to drop when the program ends. This is useful especially when you need to create thousands of datasets. But, be careful not to -save , replace- a tempfile. For instance:
tempfile blah
save `blah' , replace
is fine, but if you accidentally mistype:
save `blha', replace
then Stata will evaluate `blha' to empty and read:
save , replace
and then write over your dataset. Really, really bad.
3. It's hard to imagine -merge m:m- ever being useful.
4. Careful with using arithmetic operations instead of -egen blah=rowtotal()-. Arithmetic operations will yield missings if any variable is missing, which is not necessarily desirable, particularly when summing different forms of income/wealth/etc.
5. Use -set more off- so you don't need to keep pressing spacebar as the program runs.
6. -save blah, replace-
-clear-
-use blah-
is unnecessary. This is one of those extraneous bits of code that seems totally harmless, but unfortunately it's not always, as you can get r(603) errors sometimes when opening and closing files.
7. Use /// or /*
*/ to make all lines of code visible in the do file. (But, this is a matter of taste.)
8. Comment out -ssc install- after one run of the do file. This can slow everything down considerably, depending on the internet connection.
9. -keep x y-
-collapse (mean) x, by(y)-
is unnecessary, since collapse will only keep those variables that you mention in the command.
10. Due to Stata's multiple missing codes, use -if missing(var)- and -if !missing(var)- rather than -if var==.- and -if var!=.-