Announcement

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

  • Run Regressions With Increasing Number of Independent Vars

    Hello,

    I could not find resources online for running repeated regressions with many independent variables (which keep increasing). For example, first; I want to run three regressions regressing FP2A with each x of local empowerment, with all of the independent variables (age dummies) listed. The code I have is:

    Code:
    local empowerment decision_mker1 perm1 alone1
    
        foreach x of local empowerment{
    
            regress FP2A `x' dumm_20_24 dumm_25_29 dumm_30_34 dumm_35_39 dumm_40_44 dumm_45_49 
    
    }

    However, in addition to this regression, I want to run three more regressions; FP2A with each x of local empowerment, with the age dummies I have, and then additional independent variables dumm_primary dumm_secondary dumm_bachelors dumm_postbachelors. The code would look like:

    Code:
    local empowerment decision_mker1 perm1 alone1
    
    foreach x of local empowerment{
            regress FP2A `x' dumm_20_24 dumm_25_29 dumm_30_34 dumm_35_39 dumm_40_44 dumm_45_49 dumm_primary dumm_secondary dumm_bachelors dumm_postbachelors, robust
        }

    I will keep running the same regressions but will be adding more and more independent variables. Is there a way to simplify this process? I've tried running the code below to but it gives me not three but MANY regressions of FP2A against each individual age group.

    Code:
    local empowerment decision_mker1 perm1 alone1
        foreach x of local empowerment{
            foreach y of local agegroup{
                regress FP2A `x' `y' 
        }
    }

    Here is a data sample
    input int FP2A float(dumm_15_19 dumm_20_24 perm1 alone1 decision_mker1)
    1 0 0 -.3679239 .56009114 4.98925
    1 0 0 -.3679239 .56009114 -.20041974
    1 0 0 . . -.20042597
    1 0 0 -.3679239 .56009114 -.20042567
    1 0 0 -.3679239 .56009114 -.20042536
    1 0 0 . . -.20042595
    1 0 0 . . -.20042397
    1 0 0 -.3679239 .5600887 -.20042236
    1 0 0 -.3679239 .56009114 -.2004214
    1 0 0 2.717842 .56008655 4.989255
    0 0 0 -.3679239 -1.7853688 -.2004269
    1 0 0 2.7178476 . -.20042212

  • #2
    It may not be worth trying to program this, but you might be able to do it with multiple locals listing the variables you want to add. Then you can have the loop pick up the different locals. I think the problem in your last example is that you're looping over both empowerment and agegroup when you only want to loop over one.

    You might be able to add the variables to create multiple local macros with a separate loop if it is too much trouble to write them out.

    Comment


    • #3
      See also nestreg

      Comment


      • #4
        Based on your variable names, I'm guessing that you had a categorical variable for age and created dummies out of it. If so, that wasn't necessary. You could have just used i.agevar or something like that.

        As Phil says, there is no need to loop over the values of agegroup. Just have

        Code:
         
         regress FP2A `x' i.agevar
        or
        Code:
         
         regress FP2A `x' `agegroup'
        I also like Nick's idea to use nestreg. Note that nestreg does not allow the use of factor variables, so if you use it forget what I just said about factor variable and instead use the dummies you created.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment

        Working...
        X