I developed a program to perform regressions and numerous post-estimation commands. I'm running many regressions, so writing a program is much more efficient than copy-pasting each time. To demonstrate, consider this basic program with Stata's car dataset:
This allows me to run the program, each time specifying the independent variable and the if condition:
When the if condition does not change, like in the case above, I would like to define an object that stores the condition so that I just have to refer to that object (and not the entire condition). I have tried doing this with a global macro:
But when I then try to execute the program using the if condition:
Stata returns the error:
Do I have to redefine the global macro, and if yes, how? Alternatively, is there some other macro I could use?
Also, please note that putting the if condition into the program is not an answer. I need the program to be flexible to different if conditions.
Code:
sysuse auto.dta, clear program myProgram reg price `1' if `2' est store res_`1' end
Code:
myProgram mpg `"make!="Ford Mustang" & make!="Honda Accord""' myProgram trunk `"make!="Ford Mustang" & make!="Honda Accord""' myProgram length `"make!="Ford Mustang" & make!="Honda Accord""' myProgram weight `"make!="Ford Mustang" & make!="Honda Accord""'
Code:
global ifCondition `"make!="Ford Mustang" & make!="Honda Accord""'
Code:
myProgram mpg $ifCondition
Code:
Invalid syntax
Also, please note that putting the if condition into the program is not an answer. I need the program to be flexible to different if conditions.
Comment