Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create a loop for doing regression with multiple variables and storing each estimate with a sequential label

    Hi I'm new to Stata and have a question about using foreach for regression.

    I have A as a dependent variable, B as an independent variable, and a list of control variables including dummy variables (var1 var2 var3 i.var4 i.var5...).
    So what I want to do is to create a loop for multiple regression and then store each resulting estimate with labels like reg1, reg2, and so on.
    I looked up on Statalist and found a way to do the first part,

    Code:
    local predictors B var1 var2 var3 i.var4 i.var5 
    
    local regressors
    
    foreach p of local predictors {
    local regressors `regressors' `p'
    regress A `regressors' 
    }
    Could anyone please help me how to add the code for storing the estimates?
    I tried doing something with estimates store but it didn't work..

    Also could you tell me if I could use foreach using something like foreach X of varlist instead of local predictors?

    Many thanks!!!

  • #2
    You didn't get a quick answer. You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    estimates store reg`p' or estimates save reg`p' right after the regress statement will store the estimates. reg could be any name you like. You probably didn't change the name you used to store the results.

    Comment

    Working...
    X