In my .do file, I am asking the user some questions about what regressions they want to run, using display _request(macroname)
. Then I interpret their answer (which is either yes
or no
in most cases) and define another macro that appears in the regression code. I'm doing this as there are lots of different options of which regression to run and this makes it easy to select which one to run.
Now I want to automate a process, which loops through all the different options and I thought it would be nice to add in an extra question at the start. This will be asking whether the user also doesn't want to bother with answering questions, but to run the 64 combinations (the output of which will save to various appropriately named different Word documents).
So I have the code for the regressions that needs to be run, but it needs to either be run only once after asking five questions, or looped.
Can I save the code to a macro and then stipulate when the code should be run?
Edit: My best solution is to run a separate .do file using the do
command. If I need to do this more often, can this be done without running a separate .do file?
********************** Regressions ***********************
* If you haven't yet installed estout on your machine, you need to do that.
ssc install estout
pause Note that the regressions will be put in $DataOUT
capture window stopbox rusure "DO YOU WANT TO RUN EVERY POSSIBLE REGRESSION?" "This might take about 10 minutes."
if _rc == 0 {
global cheat_yn = "yes"
}
if _rc == 1 {
global cheat_yn = "no"
}
if "$cheat_yn" != "yes" {
/* Great! You're now at the end of the .do file! I'm going to ask you to type
in answers to some questions, to determine what variables you want to work
with. Just type in your answer in the command field, and press enter. */
* 1. Please enter a dependent variable out of searches, encouraged, employed or participates
display _request(dep)
* 2. Grant X female recipient interaction? Enter yes or no.
display _request(gXf_yn)
* 3. Grant X matric interaction? Enter yes or no.
display _request(gXmat)
* 4. Define grant independent variable to include 3 or 5 grant types? Enter 3 or 5.
display _request(n_3_5)
* 5. Dummy for grant or income? Enter dummy or income. (Note that the sample with dummy includes households with no grant income whereas the sample with the income variable only includes households with a positive grant income.)
display _request(grantd)
* 6. Separate out grant into different types or not? Enter yes or no.
display _request(separate)
do "$DataIN\running_regressions.do"
}
if "$cheat_yn" == "yes" {
pause off
foreach dependent in employed participates encouraged searches {
global dep = "`dependent'"
foreach f in no yes {
global gXf_yn = "`f'"
foreach d in income dummy {
global grantd = "`d'"
foreach s in no yes {
global separate = "`s'"
foreach n in 3 5 {
global n_3_5 = "`n'"
foreach m in yes no {
global gXmat = "`m'"
if ( "`dependent'" != "searches" & "`dependent'" != "encouraged" ) | "`f'" != "yes" | "`d'" != "dummy" | "`s'" != "yes" {
* The previous line removes a few regressions that don't run properly
do "$DataIN\running_regressions.do"
}
}
}
}
}
}
}
}