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

  • New on SSC: stackreg – stacked linear regression analysis to facilitate testing of hypotheses across OLS regressions

    Thanks to Kit Baum, a new package called stackreg is available on SSC.

    In empirical work, researchers frequently test hypotheses of parallel form in several regressions, which raises concerns about multiple testing. One way to address the multiple testing issue is to jointly test the hypotheses (e.g. Pei et al. 2019; Lee and Lemieux 2010). While the existing commands suest (Weesie 1999) and mvreg enable Stata users to follow this approach, both are limited in several dimensions. For instance, mvreg assumes homoscedasticity and uncorrelatedness across sampling units and both commands are not designed to be used with panel data. stackreg overcomes the aforementioned limitations and allows for some settings and features that go beyond the capabilities of the existing commands. To achieve this, stackreg runs an ordinary least-squares regression in which the regression equations are stacked as for instance described in Wooldridge (2010, p.166–173), and applies cluster-robust variance-covariance estimation.

    Lee, D. S. and Lemieux, T. (2010). Regression discontinuity designs in economics, Journal of Economic Literature 48(2): 281–355.
    Pei, Z., Pischke, J.-S. and Schwandt, H. (2019). Poorly measured confounders are more useful on the left than on the right, Journal of Business & Economic Statistics 37(2): 205–216.
    Weesie, J. (1999). Seemingly unrelated estimation and the cluster-adjusted sandwich estimator, Stata Technical Bulletin 52: 34–47.
    Wooldridge, J. M. (2010). Econometric Analysis of Cross Section and Panel Data, 2 edn, MIT Press, Cambridge Massachusetts.

    Best wishes,
    Michael Oberfichtner

  • #2
    Dear Michael, Thanks for sharing with us this helpful command. In fact, I have discussed with my younger son (a second-year master student) a few weeks ago that there should be a paper/technique (along with Stata command) to test the equality of coefficients across equations and/or subsamples. Since I haven't had a chance to read your article (forthcoming in Stata Journal?), I'd proceed to ask the following question and wonder if you can share your suggestions. Thanks.
    webuse grunfeld, clear
    xtset company year
    xtreg invest mvalue kstock if company < 6, fe robust
    xtreg invest mvalue kstock if company > 5, fe robust
    My question is how to test, for example, the coefficients on "mvalue" variable across these two regressions (actually using two subsamples)?
    Ho-Chuan (River) Huang
    Stata 16.1, MP(4)


    • #3
      For those having a hard time (like me) finding the required package cgmreg.ado, authored by Sergio Correia, it can be found here, as was noted byWilliam Lisowski here.


      • #4
        Dear River,
        since you want to test the equality of coefficients across models that are estimated using different subsamples, things are very straight forward. Since there is no overlap of the two estimation samples, the covariance is known to be zero and one can calculate e.g. a t-statistic simple from the estimates coefficients and the estimated standard errors; see below.
        One can of course also use xtstackreg, which requires some beforehand data manipulation to select different subsamples for estimating the different equations.
        Best wishes,

        webuse grunfeld, clear
        xtset company year
        ** Simple approach **
        xtreg invest mvalue kstock if company < 6, fe robust
        local bmvalue_a = _b[mvalue]
        local semvalue_a = _se[mvalue]
        xtreg invest mvalue kstock if company > 5, fe robust
        local bmvalue_b = _b[mvalue]
        local semvalue_b = _se[mvalue]
        local tstat = (`bmvalue_a'-`bmvalue_b')/(`semvalue_a'^2+`semvalue_b'^2)^0.5
        local pval = 2*(1-abs(normal(`tstat')))
        di as text "Test of equal coefficients; t-statistic: " as result `tstat' as text "; p-value: " as result `pval'
        ** Test using XTSTACKREG **
        gen invest_a =.
        replace invest_a = invest if company < 6
        gen invest_b =.
        replace invest_b = invest if company > 5
        xtstackreg invest_a invest_b = mvalue kstock, nocommon
        test [invest_a]mvalue-[invest_b]mvalue = 0


        • #5
          Seems to me like too much work when only an indicator is required.

          webuse grunfeld, clear
          gen subsample1= company < 6
          xtreg invest i.subsample1##(c.mvalue c.kstock), fe robust

          . xtreg invest i.subsample1##(c.mvalue c.kstock), fe robust
          note: 1.subsample1 omitted because of collinearity
          Fixed-effects (within) regression               Number of obs     =        200
          Group variable: company                         Number of groups  =         10
          R-sq:                                           Obs per group:
               within  = 0.7818                                         min =         20
               between = 0.8192                                         avg =       20.0
               overall = 0.8058                                         max =         20
                                                          F(4,9)            =      41.89
          corr(u_i, Xb)  = -0.3599                        Prob > F          =     0.0000
                                                (Std. Err. adjusted for 10 clusters in company)
                              |               Robust
                       invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                 1.subsample1 |          0  (omitted)
                       mvalue |   .0826851    .026561     3.11   0.012     .0226001    .1427702
                       kstock |   .1144632   .0133046     8.60   0.000     .0843661    .1445602
          subsample1#c.mvalue |
                           1  |    .032236   .0302849     1.06   0.315    -.0362732    .1007452
          subsample1#c.kstock |
                           1  |   .2067213   .0504928     4.09   0.003     .0924986     .320944
                        _cons |  -44.98113   20.41833    -2.20   0.055     -91.1706    1.208344
                      sigma_u |  92.050903
                      sigma_e |  51.307148
                          rho |  .76296842   (fraction of variance due to u_i)