11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

244 [ U ] 18 Programming Statabegin fvaratio.ado, version 3program fvaratioversion 11predict hii if e(sample), hatpredict ei if e(sample), residgen di2 = (ei*ei)/e(rss)// changed this versiongen FVi = (e(N)-(e(df_m)+1)) / (e(N)-(e(df_m)+2)) * ///(1 - di2/(1-hii)) / (1-hii)drop hii ei di2endend fvaratio.ado, version 3Our program is now shorter and faster, and it is completely general. This program is probably goodenough for most users; if you were implementing this solely for your own occasional use, you couldstop right here. The program does, however, have the following deficiencies:1. When we use it with data with missing values, the answer is correct, but we see messagesabout the number of missing values generated. (These messages appear when the program isgenerating the working variables.)2. We cannot control the name of the variable being produced—it is always called FVi. Moreover,when FVi already exists (say, from a previous regression), we get an error message that FVialready exists. We then have to drop the old FVi and type fvaratio again.3. If we have created any variables named hii, ei, or di2, we also get an error that the variablealready exists, and the program refuses to run.Fixing these problems is not difficult. The fix for problem 1 is easy; we embed the entire programin a quietly block:begin fvaratio.ado, version 4program fvaratioversion 11quietly {// new this versionpredict hii if e(sample), hatpredict ei if e(sample), residgen di2 = (ei*ei)/e(rss)gen FVi = (e(N)-(e(df_m)+1)) / (e(N)-(e(df_m)+2)) * ///(1 - di2/(1-hii)) / (1-hii)drop hii ei di2} // new this versionendend fvaratio.ado, version 4The output for the commands between the quietly { and } is now suppressed—the result is thesame as if we had put quietly in front of each command.Solving problem 2—that the resulting variable is always called FVi—requires use of the syntaxcommand. Let’s put that off and deal with problem 3—that the working variables have nice nameslike hii, ei, and di2, and so prevent users from using those names in their data.One solution would be to change the nice names to unlikely names. We could change hii toMyHiiVaR, which would not guarantee the prevention of a conflict but would certainly make it unlikely.It would also make our program difficult to read, an important consideration should we want to changeit in the future. There is a better solution. Stata’s tempvar command (see [U] 18.7.1 Temporaryvariables) places names into local macros that are guaranteed to be unique:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!