Announcement

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

  • Save intercept for each firm and date

    Dear all,

    I hope somebody can help me out on this.


    I am doing an fixed effects regression on panel data. Now I want to save the intercept/ constant of this regression for each firm at each date.
    My guess is that I have to do this with a loop code, however I cant figure it out. The dataset that I am using has multiple firms, and for each firm variables in dates in a range from 1-1-2013 til 31-12-2018.
    Now I do the following, simple, regression:

    xtset firmID date
    xtreg Yielddifference BAdifference, fe

    I want to save, and use the intercepts/ constants of this regression to use for further analysis. For example, to see how it difference across firms, and for 1 firm how it differs over time.


    Can somebody tell me how I should save these constants for each row?

    This was my guess;

    Code:
     gen alpha = .
     foreach id of local ID {
     
         quietly xtreg Yielddifference BADifference, fe
         quietly replace alpha = _b[_cons]
     
     }

    However, the alpha's are not replaced by the constant. Can somebody tell me what I am doing wrong, and how I should approach this in the correct way?

    Many thanks in advance,

    Paul.





    An example of my data. Note that I have multiple FirmIDs. But I specificcaly want the constant for each ID ( thus for example for FirmID 1, at each date).



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float ID byte firmID int date double(Yielddifference BAdifference) byte(E F) str7 G double(Yielddiff BAdiff)
      1 1 21000 -.17639130434782668 .20451627906977882 . . "" . .
      2 1 21003 -.20460869565217177 .20496279069767373 . . "" . .
      3 1 21004 -.15704347826086895 .20451627906977096 . . "" . .
      4 1 21005 -.14686956521738903  .2045162790697773 . . "" . .
      5 1 21006 -.06339130434782358 .20496279069768006 . . "" . .
      6 1 21007 -.07239130434782659 .20540930232558283 . . "" . .
      7 1 21010 -.06221739130434578 .20540930232558918 . . "" . .
      8 1 21011 -.05921739130434478 .20451627906976308 . . "" . .
      9 1 21012 -.06873913043478286  .2054093023255813 . . "" . .
     10 1 21013 -.10330434782608489 .20340930232559384 . . "" . .
     11 1 21014 -.08160869565217244 .20440930232557808 . . "" . .
     12 1 21017 -.11200000000000188  .2044093023255844 . . "" . .
     13 1 21018 -.15791304347825808 .20840930232558294 . . "" . .
     14 1 21019 -.24308695652173284 .19896279069766565 . . "" . .
     15 1 21020  -.2744782608695706 .20340930232557963 . . "" . .
     16 1 21021  -.3225652173912943 .20440930232558438 . . "" . .
     17 1 21024  -.3410869565217318 .20440930232558438 . . "" . .
     18 1 21025  -.3579565217391272  .2039627906976611 . . "" . .
     19 1 21026  -.4173913043478299 .20396279069767528 . . "" . .
     20 1 21027  -.4833478260869537 .20396279069768317 . . "" . .
     21 1 21028  -.3257391304347834 .20396279069768952 . . "" . .
     22 1 21031  -.3888260869565192  .2044093023255923 . . "" . .
     23 1 21032 -.30904347826086376 .20396279069768314 . . "" . .
     24 1 21033 -.23026086956521397  .2038558139534824 . . "" . .
     25 1 21034  -.3477826086956499  .2039627906976753 . . "" . .
     26 1 21035  -.2781739130434788 .20340930232557963 . . "" . .
     27 1 21038  -.5363043478260945 .20396279069768164 . . "" . .
     28 1 21039 -.40660869565217794 .20240930232558274 . . "" . .
     29 1 21040  -.4194782608695711  .2007488372093036 . . "" . .
     30 1 21041    -.43517391304347  .2029627906976784 . . "" . .
     31 1 21042 -.40508695652174076 .20440930232559226 . . "" . .
     32 1 21045  -.4786956521739114 .20496279069768006 . . "" . .
     33 1 21046  -.5473043478260893  .2044093023255844 . . "" . .
     34 1 21047  -.5052173913043561 .20440930232557805 . . "" . .
     35 1 21048  -.6157391304347799 .20440930232557805 . . "" . .
     36 1 21049 -1.0056086956521755  .2044093023255923 . . "" . .
     37 1 21052  -.5870434782608722  .2038558139534824 . . "" . .
     38 1 21053  -.5619999999999941 .20340930232557963 . . "" . .
     39 1 21054  -.7586521739130498 .20440930232559226 . . "" . .
     40 1 21055  -.7511304347826107  .2034093023255875 . . "" . .
     41 1 21056  -.8092173913043545 .19949767441860322 . . "" . .
     42 1 21059  -.8167391304347804  .2039627906976753 . . "" . .
     43 1 21060  -.8746521739130362  .2039627906976753 . . "" . .
     44 1 21061  -.7512608695652165 .20340930232557963 . . "" . .
     45 1 21062  -.7166956521739225  .2029627906976784 . . "" . .
     46 1 21063  -.7519130434782655 .20440930232559226 . . "" . .
     47 1 21066  -.6380869565217386 .20440930232559226 . . "" . .
     48 1 21067    -.65895652173913 .20174883720930836 . . "" . .
     49 1 21068  -.4390869565217388 .20385581395349026 . . "" . .
     50 1 21069  -.1701304347826058  .2044093023255844 . . "" . .
     51 1 21070  -.2303913043478314 .20385581395349026 . . "" . .
     52 1 21073 -.19952173913043492 .20485581395348082 . . "" . .
     53 1 21074 -.17178260869565332 .20485581395348718 . . "" . .
     54 1 21075  -.1671304347826048 .20485581395348718 . . "" . .
     55 1 21076   -.156956521739132  .2043023255813915 . . "" . .
     56 1 21077 -.21804347826086978 .20485581395348718 . . "" . .
     57 1 21080  -.1903478260869571  .2038558139534966 . . "" . .
     58 1 21081   -.341782608695647 .20385581395348237 . . "" . .
     59 1 21082  -.4252173913043569 .20385581395348873 . . "" . .
     60 1 21083  -.5158695652173879 .20485581395348718 . . "" . .
     61 1 21084  -.4886521739130396 .20385581395348873 . . "" . .
     62 1 21087  -.4846521739130374 .20485581395348718 . . "" . .
     63 1 21088 -.45760869565216566 .20485581395348718 . . "" . .
     64 1 21089 -.46995652173912905 .20440930232559862 . . "" . .
     65 1 21090  -.5178695652173921 .20085581395348226 . . "" . .
     66 1 21091 -.42186956521738583 .20574883720929904 . . "" . .
     67 1 21094                   .                  . . . "" . .
     68 1 21095                   .                  . . . "" . .
     69 1 21096                   .                  . . . "" . .
     70 1 21097                   .                  . . . "" . .
     71 1 21098                   .                  . . . "" . .
     72 1 21101 -.40686956521738615 .20596279069767062 . . "" . .
     73 1 21102 -.37247826086956337 .20485581395348082 . . "" . .
     74 1 21103 -.34426086956521385  .2038558139534966 . . "" . .
     75 1 21104  -.3521304347826115 .20430232558138361 . . "" . .
     76 1 21105  -.3294347826086934  .2038558139534824 . . "" . .
     77 1 21108  -.2939130434782644 .20385581395348873 . . "" . .
     78 1 21109 -.37008695652173706  .2028558139534776 . . "" . .
     79 1 21110  -.4330000000000078  .2028558139534776 . . "" . .
     80 1 21111  -.4183043478260897  .2028558139534918 . . "" . .
     81 1 21112 -.36086956521738767 .20285581395349184 . . "" . .
     82 1 21115  -.4712173913043456 .20285581395348398 . . "" . .
     83 1 21116  -.4785652173913091 .20330232558139308 . . "" . .
     84 1 21117 -.48026086956522995 .20185581395348706 . . "" . .
     85 1 21118  -.5891304347826072  .1314093023255769 . . "" . .
     86 1 21119   -.502173913043487 .11940930232559066 . . "" . .
     87 1 21122  -.3555217391304373 .03685581395349502 . . "" . .
     88 1 21123  -.6671304347826048 .17396279069768203 . . "" . .
     89 1 21124  -.5632608695652275  .1994093023255684 . . "" . .
     90 1 21125 -.21891304347825802  .2038558139534966 . . "" . .
     91 1 21126 -.31008695652173124 .20340930232557963 . . "" . .
     92 1 21129 -.24947826086956404  .2038558139534966 . . "" . .
     93 1 21130  -.3693913043478281  .2028558139534997 . . "" . .
     94 1 21131  -.3840434782608657 .20240930232557486 . . "" . .
     95 1 21132   -.344434782608702 .20340930232559384 . . "" . .
     96 1 21133  -.3202608695652174 .19985581395349958 . . "" . .
     97 1 21136  -.6505217391304416  .1924093023255918 . . "" . .
     98 1 21137  -.6042608695652278  .1944093023255793 . . "" . .
     99 1 21138   -.599782608695655 .18640930232559158 . . "" . .
    100 1 21139  -.5363043478260838 .20551627906977574 . . "" . .
    end
    format %tdnn/dd/CCYY date






  • #2
    Your guess just loops over the same regression again and again and replaces the same intercept in all observations. Nothing in your syntax selects one identifier at a time.

    But: What is the definition of

    local ID

    as I can't see it that or at least where you have defined it. A local macro has to be defined explicitly.

    Also,

    1. An xtreg for one identifier does not seem different from a regress for the same identifier in terms of intercept estimate.

    2. You have daily data but (firm, date) couples just define single observations. The intercept for a regression with single observations could I suppose be defined as each individual outcome value, but that cannot plausibly be what you mean. It could be that what you are driving towards is something like a separate regression for each year but nothing in your syntax grapples with that.

    Comment


    • #3
      Further

      3. Sometimes people work with a moving window, but you'd need to be clear whether that is what you want and if so, how you define windows.

      Comment


      • #4
        Perhaps what you want is the -predict , u- which returns the individual intercepts after -xtreg ,fe- This will give the same values (once you add in the overall constant reported by -xtreg,fe-) as if you used dummy variables in regress:

        Code:
        . webuse grunfeld,clear
        
        . qui xtreg inve mval,fe
        
        . qui predict u,u
        
        . qui replace u  = u+ _b[_cons]
        
        . tab u
        
         u[company] |      Freq.     Percent        Cum.
        ------------+-----------------------------------
           -266.324 |         20       10.00       10.00
          -214.8799 |         20       10.00       20.00
          -84.49925 |         20       10.00       30.00
          -45.50152 |         20       10.00       40.00
          -24.31194 |         20       10.00       50.00
          -21.46365 |         20       10.00       60.00
          -10.38181 |         20       10.00       70.00
           17.85155 |         20       10.00       80.00
           19.15374 |         20       10.00       90.00
           36.06968 |         20       10.00      100.00
        ------------+-----------------------------------
              Total |        200      100.00
        
        . reg invest mval ibn.com, nocon
        
              Source |       SS           df       MS      Number of obs   =       200
        -------------+----------------------------------   F(11, 189)      =    148.52
               Model |  12208389.6        11   1109853.6   Prob > F        =    0.0000
            Residual |  1412316.51       189  7472.57415   R-squared       =    0.8963
        -------------+----------------------------------   Adj R-squared   =    0.8903
               Total |  13620706.1       200  68103.5304   Root MSE        =    86.444
        
        ------------------------------------------------------------------------------
              invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              mvalue |   .1898776   .0179944    10.55   0.000     .1543819    .2253733
                     |
             company |
                  1  |  -214.8799   80.34482    -2.67   0.008    -373.3677   -56.39209
                  2  |   36.06969   40.40532     0.89   0.373    -43.63364     115.773
                  3  |   -266.324   39.92423    -6.67   0.000    -345.0784   -187.5697
                  4  |  -45.50152   23.00494    -1.98   0.049    -90.88095   -.1220946
                  5  |   17.85154   19.77315     0.90   0.368    -21.15287    56.85595
                  6  |  -24.31194   20.75356    -1.17   0.243     -65.2503    16.62643
                  7  |   19.15374    19.5165     0.98   0.328    -19.34441    57.65189
                  8  |  -84.49925   22.78985    -3.71   0.000    -129.4544   -39.54411
                  9  |  -21.46365   20.24042    -1.06   0.290    -61.38981    18.46251
                 10  |  -10.38181   19.37156    -0.54   0.593    -48.59405    27.83044
        ------------------------------------------------------------------------------

        Comment

        Working...
        X