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