Announcement

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

  • make prediction using parts of FEs after reghdfe

    Dear all,

    I want to gain predicted value after regression while eliminating some fixed effects. For example:
    Code:
    reghdfe y_mjt x_mjt, abs(D_jt D_mj D_mt)
    The predicted value I need is
    Code:
     beta1*x_mjt+beta2*D_mj+beta3*D_mt
    , where the fixed effect D_jt is not included. From the help file of reghdfe, I know predict xdb can generate linear prediction with all fixed effects. But I am curious whether I can keep parts of FEs.

    Thanks in advance!

    Haiyan

  • #2
    EDITED

    reghdfe is from SSC, as you are asked to explain (FAQ Advice #12). There shouldn't be a constant term estimated for fixed effects models, so I think that the artificial constant is interfering with the output from predict. The linear prediction excluding the fixed effects is the default -xb- prediction.

    Code:
    reghdfe y_mjt x_mjt, abs(D_jt D_mj D_mt) nocons
    predict yhat, xb
    So to achieve what you want, save the fixed effects and add them up excluding whatever you want to exclude.

    Code:
    webuse grunfeld, clear
    reghdfe invest mvalue, a(FE1=company FE2=year) nocons res
    predict double yhat, xbd
    predict double xb, xb
    gen double yhat2= xb+ FE1+ FE2
    Res.:

    Code:
    . list invest mvalue FE1 FE2 xb yhat yhat2 in 1/30, sepby(company)
    
         +-------------------------------------------------------------------------------+
         | invest   mvalue          FE1          FE2          xb        yhat       yhat2 |
         |-------------------------------------------------------------------------------|
      1. |  317.6   3078.5   -171.93301   -5.8664421    554.0312   376.23175   376.23175 |
      2. |  391.8   4661.7   -171.93301   -43.972046   838.95642   623.05137   623.05137 |
      3. |  410.6   5387.1   -171.93301   -72.178171   969.50512   725.39394   725.39394 |
      4. |  257.7   2792.2   -171.93301   -26.193739   502.50638   304.37963   304.37963 |
      5. |  330.8   4313.2   -171.93301   -65.175423    776.2376   539.12917   539.12917 |
      6. |  461.2   4643.9   -171.93301   -42.112025   835.75294   621.70791   621.70791 |
      7. |    512   4551.2   -171.93301   -7.3670943   819.06996   639.76986   639.76986 |
      8. |    448   3244.1   -171.93301    12.850619    583.8339   424.75151   424.75151 |
      9. |  499.6   4053.7   -171.93301   -12.597947   729.53589   545.00493   545.00493 |
     10. |  547.5   4379.3   -171.93301   -15.331337   788.13341   600.86907   600.86907 |
     11. |  561.2   4840.9   -171.93301   -32.313672   871.20661   666.95994   666.95994 |
     12. |  688.1   4900.9   -171.93301   -6.6062491   882.00469   703.46543   703.46543 |
     13. |  568.9   3526.5   -171.93301    28.960937   634.65682   491.68475   491.68475 |
     14. |  529.2   3254.7   -171.93301    41.230021   585.74153   455.03855   455.03855 |
     15. |  555.1   3700.2   -171.93301     22.82336   665.91723   516.80759   516.80759 |
     16. |  642.9   3755.6   -171.93301    23.932089   675.88748   527.88656   527.88656 |
     17. |  755.9     4833   -171.93301    30.876288   869.78489   728.72817   728.72817 |
     18. |  891.2   4924.9   -171.93301    46.994138   886.32392   761.38505   761.38505 |
     19. | 1304.4   6241.7   -171.93301    58.339477   1123.3057   1009.7122   1009.7122 |
     20. | 1486.7   5593.6   -171.93301    63.707217   1006.6685    898.4427    898.4427 |
         |-------------------------------------------------------------------------------|
     21. |  209.9   1362.4    55.609784   -5.8664421   245.18828   294.93162   294.93162 |
     22. |  355.3   1807.1    55.609784   -43.972046      325.22   336.85774   336.85774 |
     23. |  469.9   2676.3    55.609784   -72.178171   481.64811   465.07973   465.07973 |
     24. |  262.3   1801.9    55.609784   -26.193739   324.28417   353.70022   353.70022 |
     25. |  230.4   1957.3    55.609784   -65.175423   352.25119   342.68555   342.68555 |
     26. |  361.6   2202.9    55.609784   -42.112025   396.45128   409.94904   409.94904 |
     27. |  472.8   2380.5    55.609784   -7.3670943    428.4136   476.65629   476.65629 |
     28. |  445.6   2168.6    55.609784    12.850619   390.27842   458.73882   458.73882 |
     29. |  361.6   1985.1    55.609784   -12.597947   357.25428   400.26612   400.26612 |
     30. |  288.2   1813.9    55.609784   -15.331337   326.44379   366.72223   366.72223 |
         +-------------------------------------------------------------------------------+
    Last edited by Andrew Musau; 11 Feb 2023, 06:40.

    Comment


    • #3
      Thank you so much Andrew Musau! Your reply is very clear and helpful!

      Comment


      • #4
        I find that the _cons is embeded in the first Fixed Effect if the reghdfe does not include the "nocons" option. That is, FE1 (reghdfe without nocons)+_cons=FE1(reghdfe with nocons). Andrew Musau

        Code:
        webuse grunfeld, clear
        reghdfe invest mvalue, a(FE1=company FE2=year) res
        gen cons= -48.70963 //get after estimation
        gen fe1nocons=FE1+cons
        list FE1 cons fe1nocons in 1/30, sepby(company)
        The results are listed below
        Code:
           +-----------------------------------+
             |        FE1        cons   fe1noc~s |
             |-----------------------------------|
          1. | -123.22337   -48.70963   -171.933 |
          2. | -123.22337   -48.70963   -171.933 |
          3. | -123.22337   -48.70963   -171.933 |
          4. | -123.22337   -48.70963   -171.933 |
          5. | -123.22337   -48.70963   -171.933 |
          6. | -123.22337   -48.70963   -171.933 |
          7. | -123.22337   -48.70963   -171.933 |
          8. | -123.22337   -48.70963   -171.933 |
          9. | -123.22337   -48.70963   -171.933 |
         10. | -123.22337   -48.70963   -171.933 |
         11. | -123.22337   -48.70963   -171.933 |
         12. | -123.22337   -48.70963   -171.933 |
         13. | -123.22337   -48.70963   -171.933 |
         14. | -123.22337   -48.70963   -171.933 |
         15. | -123.22337   -48.70963   -171.933 |
         16. | -123.22337   -48.70963   -171.933 |
         17. | -123.22337   -48.70963   -171.933 |
         18. | -123.22337   -48.70963   -171.933 |
         19. | -123.22337   -48.70963   -171.933 |
         20. | -123.22337   -48.70963   -171.933 |
             |-----------------------------------|
         21. |  104.31942   -48.70963   55.60979 |
         22. |  104.31942   -48.70963   55.60979 |
         23. |  104.31942   -48.70963   55.60979 |
         24. |  104.31942   -48.70963   55.60979 |
         25. |  104.31942   -48.70963   55.60979 |
         26. |  104.31942   -48.70963   55.60979 |
         27. |  104.31942   -48.70963   55.60979 |
         28. |  104.31942   -48.70963   55.60979 |
         29. |  104.31942   -48.70963   55.60979 |
         30. |  104.31942   -48.70963   55.60979 |
             +-----------------------------------+

        Another finding is that: changing the order within the abs(a b) will get different fixed effects. That is reghdfe y x, abs(D1=fe1 D2=fe2 D3=fe3) and reghdfe y x, abs(D2=fe2 D1=fe1 D3=fe3) will generate different fixed effects for fe1, fe2. I was wondering why this happens.

        Comment


        • #5
          I find that the _cons is embeded in the first Fixed Effect if the reghdfe does not include the "nocons" option.
          Yes, you cannot separate the "constant" and the fixed effects in FE models. See https://www.stata.com/support/faqs/s...effects-model/. The only difference is that including -nocons- removes this artificial estimate from the -xb- prediction.

          Another finding is that: changing the order within the abs(a b) will get different fixed effects. That is reghdfe y x, abs(D1=fe1 D2=fe2 D3=fe3) and reghdfe y x, abs(D2=fe2 D1=fe1 D3=fe3) will generate different fixed effects for fe1, fe2. I was wondering why this happens.
          The command does not recognize that the labeled FE1 precedes FE2. So what matters is the FE variable and the order and not the name.

          Comment


          • #6
            Thank you, Andrew, for your response! The link about how fixed effects are actually estimated in Stata is also insightful.

            I do change the order of FE variables, not just the name. The effects are different even purging out the constant term. I guess it is something related to how fixed effects are estimated in the reghdfe.

            Comment

            Working...
            X