Announcement

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

  • Regression of multiple y on the same x

    Hello,
    I need to do multiple regressions of y on the same variable x. Say I have 3 variables called A, B and C, and I am trying to do the following:
    reg A X
    reg B X
    reg C X, etc...

    Since the number of my variables is over 100, I find it troublesome to type it all out. Moreover, the defendant variables do not have names in any order (they are not called y1-y156). Is there a faster way to do these regressions?

    Thanks!

  • #2
    It's a loop. Your example could be

    Code:
    foreach y in A B C {
           regress `y' X
    }
    and for your full set of predictors there will be another loop, possibly not much more complicated but the details you give don't allow any guesses on what that might be.

    I note "defendant" as a typo for "dependent". Better terms than dependent variables include outcomes, responses, etc.

    Comment


    • #3
      Adam:
      set aside any comment about the methodological approach you're after, you may want to try:
      Code:
      . g A=runiform()*1000
      
      . g B=runiform()*1000
      
      . g C=runiform()*1000
      
      . g X=runiform()*100
      
      . foreach var of varlist A-C {
        2.                 reg `var' X
        3.         }
      
            Source |       SS           df       MS      Number of obs   =        10
      -------------+----------------------------------   F(1, 8)         =      1.37
             Model |  118457.487         1  118457.487   Prob > F        =    0.2760
          Residual |  693167.033         8  86645.8791   R-squared       =    0.1460
      -------------+----------------------------------   Adj R-squared   =    0.0392
             Total |   811624.52         9  90180.5022   Root MSE        =    294.36
      
      ------------------------------------------------------------------------------
                 A |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
                 X |   3.647896   3.119861     1.17   0.276    -3.546515    10.84231
             _cons |   164.0697   208.8193     0.79   0.455    -317.4686    645.6079
      ------------------------------------------------------------------------------
      
            Source |       SS           df       MS      Number of obs   =        10
      -------------+----------------------------------   F(1, 8)         =      0.12
             Model |  9541.11673         1  9541.11673   Prob > F        =    0.7393
          Residual |  642733.557         8  80341.6946   R-squared       =    0.0146
      -------------+----------------------------------   Adj R-squared   =   -0.1085
             Total |  652274.673         9  72474.9637   Root MSE        =    283.45
      
      ------------------------------------------------------------------------------
                 B |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
                 X |   1.035287    3.00422     0.34   0.739    -5.892457    7.963031
             _cons |   492.8982   201.0793     2.45   0.040      29.2086    956.5878
      ------------------------------------------------------------------------------
      
            Source |       SS           df       MS      Number of obs   =        10
      -------------+----------------------------------   F(1, 8)         =      1.79
             Model |   177177.76         1   177177.76   Prob > F        =    0.2175
          Residual |   790955.57         8  98869.4463   R-squared       =    0.1830
      -------------+----------------------------------   Adj R-squared   =    0.0809
             Total |   968133.33         9   107570.37   Root MSE        =    314.44
      
      ------------------------------------------------------------------------------
                 C |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
                 X |   4.461345    3.33267     1.34   0.217    -3.223805     12.1465
             _cons |   282.4766   223.0631     1.27   0.241    -231.9079    796.8612
      ------------------------------------------------------------------------------
      
      .
      PS: I'm a bit late for the party that Nick started (it's Saturday night after all!)
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X