Announcement

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

  • Loop for fixed effect regression with multiple dependent variables

    Hi all,

    I have multiple dependent variables that I wish to run a fixed effect regression for with the same IV's and same controls. Below is the code I have been trying to use but nothing seems to work. I have tried to use a similar code as the question posed here: https://www.statalist.org/forums/for...s-with-outreg2 and here https://www.statalist.org/forums/for...dent-variables

    Code:
     *list dependent variables
    local dvs x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12...etc
    
    *list independent variables
    local ivs y1 y2 y3 y4 y5 y6 y7 y8 y9 y10.. etc
    
    *list controls
    local cvs i.Year pop i.RURAL_URBAN_Categorical
    
    *Loop DV variables in the regression
    xtset ID time
    foreach DV of local dvs {
        xtreg 'DV' 'ivs' 'cvs', fe
    }
    with this one I get " ' invalid name r(198)"

    when I try this:

    Code:
     xtset ID time
    local i=1
    foreach DV of local dvs {
      xtreg 'DV' 'ivs' 'cvs',fe
      estimates store m'i'
      local 'i'='i'+1
       }
    something runs but nothing appears and when I query the estimates it says "(active results produced by xtreg; not yet stored)"

    additionally, I would like to use outreg2 to store the results but I haven't even gotten to that part yet.

    thanks for all the help.
    Last edited by Julianna Kirschner; 08 Dec 2022, 11:40.

  • #2
    Note the leftmost quote:

    Code:
    xtset ID time
    local i 0
    foreach DV of local dvs {
        local ++i    
        xtreg `DV' `ivs' `cvs', fe
        estimates store m`i'
    }
    See

    Code:
    h quotes

    Comment


    • #3
      Andrew Musau thank you so much. Seems like its always the simplest things that have me frustrated for hours (difference between ` and ')

      Comment

      Working...
      X