Hi,

I am trying to run a regression for each firm_id (gvkey) and year and store the estimated coefficients.

I am using runby from SSC.

capture program drop one_regression
program define one_regression
regress TACC AT DREVDREC PPE
foreach v of varlist AT DREVDREC PPE {
gen b_`v' = _b[`v']
}
gen n = e(N)
exit
end

runby one_regression, by(gvkey) status


However, this gives me 1identical coefficient on each variable per firm, not taking the time dimension into account.

I am dealing w (unbalanced) panel data and have xtset the data.

I have tried the same thing with asreg from SSC, but also to no avail.


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long gvkey double year float(TACC AT DREVDREC PPE)
1078 2003  -.04094195  .00004122164   .06062827   .5478664
1078 2004    -.072322  .00003743167   .01017645   .4679592
1078 2005  -.06265234 .000034761455   .09358272   .4435708
1078 2006   -.1239649  .00003431567 -.012876107   .4942122
1078 2007  -.04360444  .00002764098  .068544775   .4311385
1078 2008 -.065719396 .000025180085   .07295116   .3824521
1078 2009 -.036052585  .00002357423 .0030691414   .3886661
1078 2010   -.0784066  .00001907792   .06323205   .3314655
1078 2011   -.0713331 .000016817388   .05283371   .3029916
1078 2012  -.05560142 .000016590106  .016267002   .3140322
1078 2013   -.0139957 .000014873218    -.335228   .1914183
1078 2014  -.04549158  .00002328126 -.029097516   .2940889
1078 2015 -.008721987  .00002422774  .007903605   .3000121
1078 2016  -.05188256  .00002424419  .011734325   .2998036
1161 2002  -.02305286 .000018987583   -2.723493  .13366617
1161 2003   -.1014518  .00017796188   .08577395   1.792502
1161 2004    -.140304  .00014095735   .17492545  1.5558283
1161 2005  -.16794196  .00012748256   .08464815   .6995739
1161 2006  -.19937487  .00013721602 -.030406937  1.0067539
1161 2007   -.2334373  .00007606298     .075671   .5999848
1161 2008   -.1490909  .00008658008  .014983714   .6197402
1161 2009 -.012247557  .00013029316  -.09142983   .9765472
1161 2010   .09726812  .00011015642     .174859   .2290152
1161 2011    .0227639  .00020145044   .02482842   .4423852
1161 2012  -.17056924   .0002018571     -.21425    .447719
1161 2013      .01625        .00025   -.0749366     .43325
1161 2014  -.07032511  .00023057414   .05866737   .3873645
1161 2015  -.11521104  .00026546323   -.3956256  .26121584
1161 2016   -.1888067   .0003216468    .1514604  .28337085
1209 2002  -.16214995   .0003011141   .05406709  2.2161326
1209 2003  -.07484403   .0001177163   .07299696  1.3800118
1209 2004  -.05108197  .00010602317   .08444882  1.2936418
1209 2005  -.06614278  .00009959762   .04348243   1.286134
1209 2006  -.05744178  .00009607255  .066757895   1.305655
1209 2007  -.04066829  .00008943984    .0836526   1.349495
1209 2008  -.04653422  .00007899206   .03728334  1.1839805
1209 2009   -.0543301  .00007954627   -.1468175   1.252957
1209 2010   -.0378614  .00007675128   .04544681    1.25179
1209 2011  -.03982704  .00007404172   .06803726   1.275524
1209 2012  -.05594547  .00006997558 -.028208336  1.2627933
1209 2013  -.03324322  .00005902561  .028913006  1.1527642
1209 2014 -.067226514  .00005602209  .016333785  1.1329628
1209 2015  -.06523953  .00005624582  -.02579983  1.1448611
1209 2016  -.06377988   .0000573457 -.024175726  1.1578153
1239 2002 -.005207778   .0000553854   -3.097347 .028746074
1239 2003 -.032616533   .0005782048   .11482111   .3335461
1239 2004  -.06043249   .0005139779   .16642137   .3247266
1239 2005 .0007091578   .0004857246   .10308006  .34485325
1239 2006 -.022484465  .00043438165   .08341449   .3387951
1239 2007 -.005403863   .0003872071   -1.484453   .1852941
1239 2008  -.05493627   .0006722418 -.036446087  .28500968
1239 2009  -.06167027   .0006829715 .0037618405  .30585715
1239 2010  .011338153   .0006418428   .05871345   .3012919
1356 2002   -.3485607   .0005324034   .55000734  2.2161326
1356 2003  -.04682992  .00003354579  .029075084    .831835
1356 2004 -.025133235 .000031534797   .05661014   .8156475
1356 2005 -.013585206  .00003066638   .06935541   .8285136
1356 2006 -.012048908  .00002967711   .11101848   .8709639
1356 2007 -.014522766  .00002689401  .019354174   .8498777
1356 2008  -.02590006 .000025771204  -.08949818   .8066644
1356 2009  -.06213315  .00002643964  -.20932107   .9392682
1356 2010  -.05195987  .00002599293   .07291375   .9733313
1356 2011  -.04018528 .000025449826   .09688435   .9625124
1356 2012 -.032552343 .000024925224  -.02608328   .9505733
1356 2013  -.09614475  .00002488862  -.02089978    .917544
1356 2014  -.03933747  .00002797829  .015080617   .9937049
1356 2015  -.05091045  .00002673868  -.03027814    .900746
1408 2002 -.007156154  .00002737626  -2.7739515 .065631844
1408 2003 -.036326475   .0001717564    .0560921   .4672461
1408 2004 -.010194899  .00013432014   .01504389   .3014278
1408 2005 -.028045563  .00012684561   .04252547   .3548125
1408 2006 -.011559293  .00007574897   .10025702  .24706283
1408 2007 -.014711998 .000068174224  -.00998789   .2116128
1408 2008  -.04721679  .00007164915 -.063157976  .21665986
1408 2009  -.05156344      .0000827   -.0751944   .2530289
1408 2010  -.02287682  .00008083682   .02893028  .25655183
1408 2011 -.025340624   .0000788936   -.4997598  .09908247
1408 2012 .0026695854  .00013347928  .015190637  .18070424
1408 2013 -.006750107  .00011578228  .012825144  .16309093
1468 2002  .005133319   .0001164863  -.16810636   .1222744
1468 2003  -.07244594   .0003869789   .02918503   .3945165
1468 2004   -.1149217   .0004025744 -.022112867    .399256
1468 2005  -.07426326   .0003943796  .018610053   .3762307
1468 2006  -.10112476   .0004506612  -.05792498   .4256648
1468 2007  -.09006678    .000562362   .04022383  .54778165
1468 2008   -.1667005  .00055419223  -.05979615   .5309605
1468 2009  -.08084598   .0006974532   -.1005857   .5863461
1468 2010  -.06065501    .000653744 -.002733884   .5553894
1468 2011  -.03835194   .0006463084   .07181193  .58218104
1468 2012  -.07282905   .0006453845    .1063353   .5303505
1533 2002   -.0050819   .0006315272    -7.26601  .02682565
1533 2003  -.06334725    .007577423  -.06713872  .15617825
1533 2004 -.010109653    .009834292   -.1623405  .29767418
1533 2005   -.3020829    .009937592   .23927826    .314654
1533 2006  -.10863478    .008695652   .18435614  1.2634435
1533 2007  -.07998998     .00417615    .1755043   .6536343
1533 2008  -.04563625   .0040095104   .06041056   .6839824
1533 2009 -.068019554    .003977519  -.08649719   .7177194
1533 2010  -.09081675   .0037758504   -.1069184    .731639
1533 2011  -.10146767    .003626565   .15598735   .7488168
end