Announcement

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

  • manual prediction?

    Dear All, Suppose that I have the following results,
    Code:
    . reg spreadD2 z01-z09 maturity i.type i.asset2 i.year if split==0, noconstant //538 observations
    note: z01 omitted because of collinearity.
    note: z02 omitted because of collinearity.
    note: z03 omitted because of collinearity.
    
          Source |       SS           df       MS      Number of obs   =       527
    -------------+----------------------------------   F(20, 507)      =    685.12
           Model |  2602.49469        20  130.124735   Prob > F        =    0.0000
        Residual |  96.2947133       507  .189930401   R-squared       =    0.9643
    -------------+----------------------------------   Adj R-squared   =    0.9629
           Total |  2698.78941       527  5.12104252   Root MSE        =    .43581
    
    ------------------------------------------------------------------------------
        spreadD2 | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             z01 |          0  (omitted)
             z02 |          0  (omitted)
             z03 |          0  (omitted)
             z04 |   2.783047   .1834411    15.17   0.000     2.422649    3.143446
             z05 |   2.743212   .1715835    15.99   0.000      2.40611    3.080315
             z06 |   2.174279    .165168    13.16   0.000     1.849781    2.498777
             z07 |   1.945444    .166449    11.69   0.000     1.618429    2.272459
             z08 |   1.936486   .1587104    12.20   0.000     1.624675    2.248297
             z09 |   1.377192   .1341542    10.27   0.000     1.113625    1.640758
        maturity |   .0814115   .0109706     7.42   0.000     .0598582    .1029649
                 |
            type |
              2  |   .0595228   .0494886     1.20   0.230    -.0377052    .1567508
              3  |   .2414885     .08609     2.81   0.005     .0723515    .4106255
                 |
          asset2 |
              2  |  -.1603417   .0864387    -1.85   0.064    -.3301638    .0094805
              3  |  -.2118507   .0906293    -2.34   0.020     -.389906   -.0337954
              4  |  -.0609051   .1355407    -0.45   0.653    -.3271956    .2053854
              5  |  -.0961297   .1241528    -0.77   0.439    -.3400471    .1477877
              6  |  -.0862022   .1100055    -0.78   0.434    -.3023249    .1299205
              7  |   .0640044   .1651877     0.39   0.699    -.2605323     .388541
              8  |  -.5444096   .1945261    -2.80   0.005    -.9265861   -.1622332
                 |
            year |
           2013  |   1.113748   .2585086     4.31   0.000     .6058684    1.621628
           2014  |   .7873123    .136129     5.78   0.000     .5198659    1.054759
           2015  |   .5004605   .1337447     3.74   0.000     .2376984    .7632226
           2016  |   .3021893   .1357553     2.23   0.026     .0354771    .5689016
    How can I predict manually? It should be something like
    Code:
    gen wanted = _b[z01]*z01+_b[z02]*z02+_b[z03]*z03+_b[z04]*z04+_b[z05]*z05+_b[z06]*z06+_b[z07]*z07+_b[z08]*z08+_b[z09]*z09+...+
    In particular, how can I incorporate type, asset2, and year? Thanks.
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    Why do you want to do this?

    Comment


    • #3
      If you are trying the calculated the linear predictor, then yes this is the general approach. (If trying to predict something else, then the question is unclear.) The approach is to multiple the values of the various predictors with their covariates, adjusting for the fact that you have indicator variables for type, year and asset, so a conditional operation is needed there, then adding them all together (plus or minus a constant).

      Beyond this, I second daniel's question of why you want to do this when -predict- does this automatically. Consider a much simpler toy example.

      Code:
      sysuse auto
      reg mpg i.foreign
      predict xb
      gen xb2 = _b[_cons] + _b[1.foreign]*cond(foreign==1, 1, 0) if e(sample)
      assert xb==xb2

      Comment


      • #4
        Dear daniel, Thansk for the reply (question). I asked this question for one friend. Her problem is very complicated, and I can not understand completely. And, I think it is difficult for her to express the question clearly in English (even in Chinese).
        Ho-Chuan (River) Huang
        Stata 17.0, MP(4)

        Comment


        • #5
          Dear Leonardo, Thanks a lot. I'll give it a try.
          Ho-Chuan (River) Huang
          Stata 17.0, MP(4)

          Comment


          • #6
            Originally posted by River Huang View Post
            Her problem is very complicated, and I can not understand completely.
            All the more reason to ask why (she thinks) she wants what she is aksing for. Not understanding the underlying ultimate goal increases the risk of the XY-Problem. Also, if stuff gets complicated it is usually a better bet to look for tools developed by professionals, in this case, StataCorp. Sometimes (actually quite often) questions are more helpful than answers to think about, better understand, and then solve our own problems.

            Comment


            • #7
              River:
              as an aside to previous helpful advice, if the researcher you posted on the behalf of wants to challenge herself with manual prediction (say, to understand how Stata calculates the fitted values), an approach that I find useful is to invoke -predict-, calculate the predicted values manually and then compare the results of the two approaches. Most of the times I've learnt a lot form this strategy.
              Kind regards,
              Carlo
              (StataNow 18.5)

              Comment


              • #8
                Dear daniel, Thanks again. I will talk to her to see if we can make the question clearer.
                Ho-Chuan (River) Huang
                Stata 17.0, MP(4)

                Comment


                • #9
                  Dear Carlo, Thanks for the suggestion. It is a non-standard question so that the -predict- command does not work here.
                  Ho-Chuan (River) Huang
                  Stata 17.0, MP(4)

                  Comment


                  • #10
                    River Huang, can you post the data generating the results in #1? I am sure you can do what you want extracting the coefficient names from matrix e(b).
                    Last edited by Andrew Musau; 12 Apr 2022, 08:08.

                    Comment


                    • #11
                      Dear Andrew, Thanks for the suggestion. I have to talk to my friend to see if she is willing to share the data. I'll get back to you later.

                      Ho-Chuan (River) Huang
                      Stata 17.0, MP(4)

                      Comment

                      Working...
                      X