Announcement

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

  • Estimating indirect (mediation) effect using nlcom (Stata returns error message)

    Hello,

    I am trying to use a non linear combination to estimate an indirect effect in of X onto Q, via T (T is the mediator), at the mean of X. I am using the command nlcom

    The code i am using is the following:

    xtreg Q X <CONTROLS> i.YEAR, fe
    est store M1
    xtreg Q X T <CONTROLS> i.YEAR if, fe
    est store M2A
    xtreg T X <CONTROLS> i.YEAR, fe
    est store M2B
    global X_mean=r(mean)
    global X_stdev=r(sd)
    nlcom _b[M1:X]*[X_mean] - _b[M2A:MD]*[X_mean].


    STATA displays the following error message: equation M1 not found
    r(111);


    Note: Please note that "<CONTROLS>" is not included in the code (it's my way of indicating in the forum that there are many control variables in the model).


    Can anybody assist me? Many thanks in advance!

    Kind regards,
    Joao


  • #2
    Hello again,

    Probably my last query was had unnecessary information (I also had a small labeling error) so I will try to simplify it:

    1. I saved the estimates of 3 models (which I ran using xtreg), as well as the mean and sd values of my variable of interest (X) using the commands:

    est store M1
    est store M2A
    est store M2B
    global X_mean=r(mean)
    global X_stdev=r(sd)

    2. I then try to do nlcom as follows:

    nlcom _b[M1:X]*[X_mean] - _b[M2A:X]*[X_mean].

    However, after performing step 2., STATA displays the following error message: "equation M1 not found
    r(111);"

    I have tried restoring model M1 (and M1 it becomes active), but then STATA cannot find M2A.

    Any help would be much appreciated!

    Kind regards,
    Joao

    Comment


    • #3
      I'm afraid you're confusing estimation results with equations. Estimation results can be stored using estimates store, but this doesn't make it an equation. The eqno option can be used in postestimation commands after multiple equation esimators such as sureg.

      To combine different models for testing you can use suest, but unfortunately this doesn't work after xtreg. What you can do is to estimate your fixed effects models using regress, which means that you have to include fixed effect dummies manually. This should lead to the same results as your xtreg results. After storing the estimation results of each model you can use suest to combine the models and do your postestimation tests.

      Example:
      Code:
      . webuse grunfeld
      
      .
      . xtreg invest mvalue kstock, fe
      
      Fixed-effects (within) regression               Number of obs     =        200
      Group variable: company                         Number of groups  =         10
      
      R-sq:                                           Obs per group:
           within  = 0.7668                                         min =         20
           between = 0.8194                                         avg =       20.0
           overall = 0.8060                                         max =         20
      
                                                      F(2,188)          =     309.01
      corr(u_i, Xb)  = -0.1517                        Prob > F          =     0.0000
      
      ------------------------------------------------------------------------------
            invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            mvalue |   .1101238   .0118567     9.29   0.000     .0867345    .1335131
            kstock |   .3100653   .0173545    17.87   0.000     .2758308    .3442999
             _cons |  -58.74393   12.45369    -4.72   0.000    -83.31086     -34.177
      -------------+----------------------------------------------------------------
           sigma_u |  85.732501
           sigma_e |  52.767964
               rho |  .72525012   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      F test that all u_i=0: F(9, 188) = 49.18                     Prob > F = 0.0000
      
      . // Same results as regression above
      . reg invest mvalue kstock i.company
      
            Source |       SS           df       MS      Number of obs   =       200
      -------------+----------------------------------   F(11, 188)      =    288.50
             Model |   8836465.8        11  803315.073   Prob > F        =    0.0000
          Residual |  523478.114       188  2784.45805   R-squared       =    0.9441
      -------------+----------------------------------   Adj R-squared   =    0.9408
             Total |  9359943.92       199  47034.8941   Root MSE        =    52.768
      
      ------------------------------------------------------------------------------
            invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            mvalue |   .1101238   .0118567     9.29   0.000     .0867345    .1335131
            kstock |   .3100653   .0173545    17.87   0.000     .2758308    .3442999
                   |
           company |
                2  |   172.2025   31.16126     5.53   0.000     110.7319    233.6732
                3  |  -165.2751   31.77556    -5.20   0.000    -227.9576   -102.5927
                4  |    42.4874   43.90987     0.97   0.334    -44.13197    129.1068
                5  |  -44.32013   50.49225    -0.88   0.381    -143.9243    55.28406
                6  |   47.13539   46.81068     1.01   0.315    -45.20629    139.4771
                7  |   3.743212   50.56493     0.07   0.941    -96.00433    103.4908
                8  |   12.75103   44.05263     0.29   0.773    -74.14994      99.652
                9  |  -16.92558   48.45326    -0.35   0.727    -112.5075    78.65636
               10  |   63.72884   50.33023     1.27   0.207    -35.55572    163.0134
                   |
             _cons |  -70.29669   49.70796    -1.41   0.159    -168.3537    27.76035
      ------------------------------------------------------------------------------
      
      . estimates store M1
      
      . reg invest mvalue kstock i.company i.year
      
            Source |       SS           df       MS      Number of obs   =       200
      -------------+----------------------------------   F(30, 169)      =    110.98
             Model |  8907796.87        30  296926.562   Prob > F        =    0.0000
          Residual |  452147.043       169  2675.42629   R-squared       =    0.9517
      -------------+----------------------------------   Adj R-squared   =    0.9431
             Total |  9359943.92       199  47034.8941   Root MSE        =    51.725
      
      ------------------------------------------------------------------------------
            invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            mvalue |   .1177158   .0137513     8.56   0.000     .0905694    .1448623
            kstock |   .3579163    .022719    15.75   0.000     .3130667    .4027659
                   |
           company |
                2  |   207.0542   35.17275     5.89   0.000     137.6197    276.4887
                3  |  -135.2308   35.70897    -3.79   0.000    -205.7239   -64.73772
                4  |    95.3538   50.72211     1.88   0.062    -4.776741    195.4844
                5  |  -5.438636   57.83052    -0.09   0.925    -119.6019    108.7246
                6  |   102.8886   54.17388     1.90   0.059    -4.056071    209.8333
                7  |   51.46657   58.17922     0.88   0.378    -63.38505    166.3182
                8  |   67.49048   50.97092     1.32   0.187    -33.13125    168.1122
                9  |   30.21752   55.72307     0.54   0.588    -79.78542    140.2204
               10  |   126.8371   58.52545     2.17   0.032     11.30197    242.3722
                   |
              year |
             1936  |  -19.19741   23.67586    -0.81   0.419    -65.93593    27.54112
             1937  |  -40.69001   24.69541    -1.65   0.101    -89.44122    8.061213
             1938  |   -39.2264   23.23594    -1.69   0.093    -85.09647    6.643667
             1939  |  -69.47029   23.65607    -2.94   0.004    -116.1698   -22.77083
             1940  |  -44.23507   23.80979    -1.86   0.065      -91.238     2.76785
             1941  |  -18.80446     23.694    -0.79   0.429     -65.5788    27.96987
             1942  |  -21.13979   23.38163    -0.90   0.367    -67.29748    25.01789
             1943  |  -42.97762   23.55287    -1.82   0.070    -89.47334    3.518104
             1944  |  -43.09876    23.6102    -1.83   0.070    -89.70766    3.510134
             1945  |  -55.68303   23.89561    -2.33   0.021    -102.8554   -8.510689
             1946  |  -31.16928   24.11598    -1.29   0.198    -78.77665    16.43809
             1947  |  -39.39223   23.78368    -1.66   0.100    -86.34361    7.559141
             1948  |  -43.71651   23.96965    -1.82   0.070    -91.03501    3.601991
             1949  |   -73.4951   24.18292    -3.04   0.003    -121.2346   -25.75559
             1950  |  -75.89611   24.34553    -3.12   0.002    -123.9566    -27.8356
             1951  |   -62.4809   24.86425    -2.51   0.013    -111.5654   -13.39637
             1952  |  -64.63233    25.3495    -2.55   0.012    -114.6748   -14.58987
             1953  |  -67.71796   26.61108    -2.54   0.012    -120.2509   -15.18501
             1954  |  -93.52622   27.10786    -3.45   0.001    -147.0399   -40.01257
                   |
             _cons |  -86.90019   56.04663    -1.55   0.123    -197.5419    23.74149
      ------------------------------------------------------------------------------
      
      . estimates store M2
      
      . suest M1 M2
      
      Simultaneous results for M1, M2
      
                                                      Number of obs     =        200
      
      ------------------------------------------------------------------------------
                   |               Robust
                   |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      M1_mean      |
            mvalue |   .1101238   .0188348     5.85   0.000     .0732082    .1470394
            kstock |   .3100653   .0415954     7.45   0.000     .2285398    .3915908
                   |
           company |
                2  |   172.2025   44.06745     3.91   0.000     85.83191    258.5731
                3  |  -165.2751    42.1336    -3.92   0.000    -247.8555    -82.6948
                4  |    42.4874   63.18527     0.67   0.501    -81.35345    166.3282
                5  |  -44.32013   70.30033    -0.63   0.528    -182.1062    93.46599
                6  |   47.13539   68.20053     0.69   0.489    -86.53519     180.806
                7  |   3.743212   71.41464     0.05   0.958    -136.2269    143.7133
                8  |   12.75103   64.40243     0.20   0.843    -113.4754    138.9775
                9  |  -16.92558   68.20504    -0.25   0.804     -150.605    116.7538
               10  |   63.72884   75.51826     0.84   0.399    -84.28423    211.7419
                   |
             _cons |  -70.29669   76.85156    -0.91   0.360     -220.923     80.3296
      -------------+----------------------------------------------------------------
      M1_lnvar     |
             _cons |   7.931809   .1684385    47.09   0.000     7.601675    8.261942
      -------------+----------------------------------------------------------------
      M2_mean      |
            mvalue |   .1177158   .0176752     6.66   0.000     .0830731    .1523585
            kstock |   .3579163   .0501345     7.14   0.000     .2596544    .4561781
                   |
           company |
                2  |   207.0542   42.27979     4.90   0.000     124.1873    289.9211
                3  |  -135.2308    40.2181    -3.36   0.001    -214.0568    -56.4048
                4  |    95.3538   62.08779     1.54   0.125    -26.33603    217.0436
                5  |  -5.438636   65.75705    -0.08   0.934    -134.3201    123.4428
                6  |   102.8886   66.71839     1.54   0.123    -27.87703    233.6542
                7  |   51.46657   68.34067     0.75   0.451    -82.47868    185.4118
                8  |   67.49048   63.05639     1.07   0.284    -56.09777    191.0787
                9  |   30.21752   65.31009     0.46   0.644     -97.7879    158.2229
               10  |   126.8371    74.4061     1.70   0.088    -18.99619    272.6704
                   |
              year |
             1936  |  -19.19741   18.81824    -1.02   0.308    -56.08049    17.68567
             1937  |  -40.69001   23.24907    -1.75   0.080    -86.25734    4.877328
             1938  |   -39.2264   21.10693    -1.86   0.063    -80.59523    2.142419
             1939  |  -69.47029   27.07226    -2.57   0.010    -122.5309   -16.40964
             1940  |  -44.23507    18.8221    -2.35   0.019     -81.1257   -7.344445
             1941  |  -18.80446   18.48915    -1.02   0.309    -55.04252     17.4336
             1942  |  -21.13979   19.16364    -1.10   0.270    -58.69984    16.42026
             1943  |  -42.97762    19.3607    -2.22   0.026     -80.9239   -5.031338
             1944  |  -43.09876   22.45687    -1.92   0.055    -87.11342    .9158871
             1945  |  -55.68303   21.39705    -2.60   0.009    -97.62048   -13.74559
             1946  |  -31.16928   21.94335    -1.42   0.155    -74.17747     11.8389
             1947  |  -39.39223    21.0543    -1.87   0.061     -80.6579    1.873432
             1948  |  -43.71651   25.20204    -1.73   0.083    -93.11161    5.678582
             1949  |   -73.4951   24.02181    -3.06   0.002     -120.577   -26.41321
             1950  |  -75.89611    24.6479    -3.08   0.002    -124.2051    -27.5871
             1951  |   -62.4809   30.30456    -2.06   0.039    -121.8767   -3.085059
             1952  |  -64.63233   34.24109    -1.89   0.059    -131.7436    2.478976
             1953  |  -67.71796   35.92463    -1.89   0.059    -138.1289    2.693013
             1954  |  -93.52622   27.01574    -3.46   0.001    -146.4761   -40.57635
                   |
             _cons |  -86.90019   69.51771    -1.25   0.211    -223.1524    49.35202
      -------------+----------------------------------------------------------------
      M2_lnvar     |
             _cons |   7.891864   .1437336    54.91   0.000     7.610151    8.173577
      ------------------------------------------------------------------------------
      
      . test [M1_mean]mvalue = [M2_mean]mvalue
      
       ( 1)  [M1_mean]mvalue - [M2_mean]mvalue = 0
      
                 chi2(  1) =    1.26
               Prob > chi2 =    0.2609

      Comment


      • #4
        Also:
        global X_mean=r(mean)
        global X_stdev=r(sd)
        nlcom _b[M1:X]*[X_mean] - _b[M2A:X]*[X_mean].
        r(mean) and r(sd) are only available after summarize, so make sure you run that before.

        Finally, after assigning contents to a global, the way to refer to that global is with $.
        Code:
        . global X "Hello"
        
        . di "$X"
        Hello

        Comment


        • #5
          Dear Wouter

          Thank you very much for the detailed feedback!!

          Kind regards,
          Joao

          Comment


          • #6
            Dear Wouter,

            I just finished running the commands following your feedback. Specifically:

            -For each model I used the regress command including i.YEAR and i.firm to control for fixed effects of year and firm, respectively. Indeed, it did produce the same results as xtreg for each of the models!

            -I then used suest to combine the models and do my postestimation tests. I did r(mean) and r(sd) after summarize. After assigning contents to a global I referred to it with $.

            The nlcom estimations are now working. Thank you so much for your help!!

            Kind regards,
            Joao

            Comment

            Working...
            X