Dear Statalisters,
There have been several parallel threads on using local macros to create lists of variables when running repetitive regressions, for instance changing the outcome variable but keeping the same model variables (or vice-versa). I found these useful in learning about the foreach command.
I would like to be able to use local to create a block of variables and then loop over these blocks so that the first model would be a minimally adjusted (containing two or three variables) and then a fully adjusted model containing all the variables I wish to control for.
At the moment I have developed the following command strategy:
local predictors "x1 x2 x3 x4 x5 x6 x7"
local outcome "y1 y2"
foreach x of local predictors {
local regressors `regressors' `x'
foreach y of local outcome {
local model `y' `regressors' `x'
reg `y' `regressors'
}
}
What this does is run consecutive regressions for outcome y1 first adding in x1 to the model, then y2 adding in x1 to the model. In the next round, y1 is the outcome and then x1 and x2 are included in the model, then y2 as the outcome with x1 and x2 in the model and so forth.
Order of operations:
reg y1 x1
reg y2 x1
reg y1 x1 x2
reg y2 x1 x2
reg y1 x1 x2 x3
reg y2 x1 x2 x3 .....
My question is - can a local be defined such that I can save variables x1 x2 x3 as the 'minimally' adjusted model [i.e as block1] and then in the next round of the loop x4 x5 x6 x7 are all added in at the same time for the 'fully' adjusted model [i.e. block1 + block2].
In other words, I would like the order of operations to be:
reg y1 x1 x2 x3
reg y2 x1 x2 x3
reg y1 x1 x2 x3 x4 x5 x6 x7
reg y2 x1 x2 x3 x4 x5 x6 x7
I am using Stata v14.2
Many thanks,
Alexander
Related Posts with Using local macro to create 'blocks' of variables to be used in multivariable regression analyses
Difference-in-Difference, with IVHello everyone, I would like to ask one question that I am struggling on. I would like to estimate …
filling missing valuesDear All, I find this question here (in Chinese). The raw data is Code: * Example generated by -da…
Seemingly unrelated regression (sureg) & Testing for significant differences of a coefficient across more than two equationsI will use sureg (seemingly unrelated regression) to analyze my data. I need to test my coefficients…
Using (nested) loops to conditionally sumHello, thank you in advance for any advice you are able to provide me with. I am a rather novice whe…
checking the imputed valuesHi all, I have watched a video by chuck huber about multiple imputation. i want to know how to check…
Subscribe to:
Post Comments (Atom)
0 Response to Using local macro to create 'blocks' of variables to be used in multivariable regression analyses
Post a Comment