I am performing an event study and am trying to estimate the beta of 60 different public companies during an estimation window so that I can apply these predicted betas and apply them to my event window and calculate the expected return via the CAPM model. I have a dataset with each company event_id, date of observation date, stock_return, market_return, risk_free_rate and a couple of dummies indicating if the date referred is during the event period (event_window = 0 or 1) and the same for event window (event_window).

I have done the following, but seem to not be getting a constant stock beta for each company.

code

[CODE]
. use event_study, clear
. sort event_id date
. generate expected_return=.
. egen id=group(event_id)
. codebook id

forvalues i=1(1)62 {
l id event_id if id==`i' & dif==0
reg stock_return market_return if id==`i' & estimation_window==1
predict p if id==`i'
replace expected_return = mean(p) if id==`i' & event_window==1
drop p
}
[CODE]

data example

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str13 event_id int date float(stock_return market_return risk_free mkt_cap_growth event_dummy dif event_window estimation_window)
"AAP32008" 17273 -.12430082   .20476545 .013424657 . 0 -249 0 1
"AAP32008" 17274  -.4987541   .06929395 .013424657 . 0 -248 0 1
"AAP32008" 17275  .22474726  -.12027604 .013424657 . 0 -247 0 1
"AAP32008" 17276  1.7555155     .921809 .013424657 . 0 -246 0 1
"AAP32008" 17279   .9513427   -.2306697 .013424657 . 0 -245 0 1
"AAP32008" 17280  -.3161097 -.035119236 .013424657 . 0 -244 0 1
"AAP32008" 17281    2.88066   1.0088028 .013424657 . 0 -243 0 1
"AAP32008" 17282 -1.1662633  -.07826951 .013424657 . 0 -242 0 1
"AAP32008" 17283  -.2396933 -.012046902 .013424657 . 0 -241 0 1
"AAP32008" 17286  -1.134319   -.7861781 .013123288 . 0 -240 0 1
"AAP32008" 17287  -.6330676   .26476517 .013123288 . 0 -239 0 1
"AAP32008" 17288    .875492    .6451592 .013123288 . 0 -238 0 1
"AAP32008" 17289  -1.389758    .4315771 .013123288 . 0 -237 0 1
"AAP32008" 17290  -.9373527      .21476 .013123288 . 0 -236 0 1
"AAP32008" 17293  .14858843   .25604472 .013123288 . 0 -235 0 1
"AAP32008" 17294   3.262217  -.11666447 .013123288 . 0 -234 0 1
"AAP32008" 17295   .5970167    .3218226 .013123288 . 0 -233 0 1
"AAP32008" 17296  -.7648221   -1.405459 .013123288 . 0 -232 0 1
"AAP32008" 17297  -.4810014    .9595312 .013123288 . 0 -231 0 1
"AAP32008" 17300   -1.65293  -.17946166 .013123288 . 0 -230 0 1
"AAP32008" 17301  -.8121123  -.13047792 .013123288 . 0 -229 0 1
"AAP32008" 17302  .09878983    .8589494 .013123288 . 0 -228 0 1
"AAP32008" 17303  2.0523565  -.09184345 .013123288 . 0 -227 0 1
"AAP32008" 17304 -.07257772    .6588724 .013123288 . 0 -226 0 1
"AAP32008" 17307   .7714599    .1542071 .013123288 . 0 -225 0 1
"AAP32008" 17308 -1.2809843  -.06427874 .013123288 . 0 -224 0 1
"AAP32008" 17309    -.17042  -.12079833 .013123288 . 0 -223 0 1
"AAP32008" 17310 -1.3739176   -.9749928 .013123288 . 0 -222 0 1
"AAP32008" 17311 -.12359414    .5437888 .013123288 . 0 -221 0 1
"AAP32008" 17314          0           0 .013123288 . 0 -220 0 1
"AAP32008" 17315   .6164488    .1568969 .013123288 . 0 -219 0 1
"AAP32008" 17316  1.4399272     .795191 .013123288 . 0 -218 0 1
"AAP32008" 17317   .3628012   .02548312  .01260274 . 0 -217 0 1
"AAP32008" 17318   .4576667    .3730082  .01260274 . 0 -216 0 1
"AAP32008" 17321   .8852791   .18468426  .01260274 . 0 -215 0 1
"AAP32008" 17322 -.19074875  -.53613496  .01260274 . 0 -214 0 1
"AAP32008" 17323 -1.5634714   -.8903294  .01260274 . 0 -213 0 1
"AAP32008" 17324 -1.5883046   -1.772594  .01260274 . 0 -212 0 1
"AAP32008" 17325   3.485348   1.1306188  .01260274 . 0 -211 0 1
"AAP32008" 17328 -1.1242793   .09612867  .01260274 . 0 -210 0 1
"AAP32008" 17329 -1.5026942  -1.0739181  .01260274 . 0 -209 0 1
"AAP32008" 17330  .24390256   1.5070066  .01260274 . 0 -208 0 1
"AAP32008" 17331 -.12187692     .480479  .01260274 . 0 -207 0 1
"AAP32008" 17332          0    .6505514  .01260274 . 0 -206 0 1
"AAP32008" 17335  -.4154961  -.12141152  .01260274 . 0 -205 0 1
"AAP32008" 17336   .8535596    .1729342  .01260274 . 0 -204 0 1
"AAP32008" 17337  -.4136762  -1.3694438  .01260274 . 0 -203 0 1
"AAP32008" 17338 -1.4986154    .6161408  .01260274 . 0 -202 0 1
"AAP32008" 17339  -.7702858  -1.2979767  .01260274 . 0 -201 0 1
"AAP32008" 17342  -.5753612   -.3213015  .01260274 . 0 -200 0 1
"AAP32008" 17343 -1.3894376   -.3243467  .01260274 . 0 -199 0 1
"AAP32008" 17344  4.2580814    .8969029  .01260274 . 0 -198 0 1
"AAP32008" 17345  -.4887595  -.04183197  .01260274 . 0 -197 0 1
"AAP32008" 17346  -.7129717  -.15685965 .012821917 . 0 -196 0 1
"AAP32008" 17349  1.2261065   1.0639313 .012821917 . 0 -195 0 1
"AAP32008" 17350  .53476065    .3573896 .012821917 . 0 -194 0 1
"AAP32008" 17351          0           0 .012821917 . 0 -193 0 1
"AAP32008" 17352   .6524126  .034751024 .012821917 . 0 -192 0 1
"AAP32008" 17353   .9587801    .3298605 .012821917 . 0 -191 0 1
"AAP32008" 17356 -1.1033933   .09208795 .012821917 . 0 -190 0 1
"AAP32008" 17357  -2.589932  -1.4287038 .012821917 . 0 -189 0 1
"AAP32008" 17358  -.9950331   .57050943 .012821917 . 0 -188 0 1
"AAP32008" 17359          0   1.8875746 .012821917 . 0 -187 0 1
"AAP32008" 17360  -.5012542    .3096577 .012821917 . 0 -186 0 1
"AAP32008" 17363   -.301963   -.1921329 .012821917 . 0 -185 0 1
"AAP32008" 17364  .02519844 -.009680886 .012821917 . 0 -184 0 1
"AAP32008" 17365 -1.0893078  -.20674914 .012821917 . 0 -183 0 1
"AAP32008" 17366   -.741407    .4459151 .012821917 . 0 -182 0 1
"AAP32008" 17367  -.4887469  -1.2296166 .012821917 . 0 -181 0 1
"AAP32008" 17370  .28324983    .4857488 .012821917 . 0 -180 0 1
"AAP32008" 17371  -.9559561   -2.000322 .012821917 . 0 -179 0 1
"AAP32008" 17372 -1.4908084     .465481 .012821917 . 0 -178 0 1
"AAP32008" 17373  -4.859255  -2.3615193 .012821917 . 0 -177 0 1
"AAP32008" 17374 -3.0330884  -1.6120774 .012821917 . 0 -176 0 1
"AAP32008" 17377   .4835737   1.0201734 .012821917 . 0 -175 0 1
"AAP32008" 17378 -1.3426855  -1.2727283  .01320548 . 0 -174 0 1
"AAP32008" 17379 -1.0698382    .7216541  .01320548 . 0 -173 0 1
"AAP32008" 17380  2.0144565     .434989  .01320548 . 0 -172 0 1
"AAP32008" 17381 -4.1593895   -2.694586  .01320548 . 0 -171 0 1
"AAP32008" 17384  1.0635256    2.386409  .01320548 . 0 -170 0 1
"AAP32008" 17385  -.6190145    .6140531  .01320548 . 0 -169 0 1
"AAP32008" 17386 -4.1660113   1.3973733  .01320548 . 0 -168 0 1
"AAP32008" 17387  -6.791454   -3.009805  .01320548 . 0 -167 0 1
"AAP32008" 17388    4.79886   .03784321  .01320548 . 0 -166 0 1
"AAP32008" 17391   5.267599   -.0495431  .01320548 . 0 -165 0 1
"AAP32008" 17392 -2.2323701  -1.8323393  .01320548 . 0 -164 0 1
"AAP32008" 17393  -3.666145  -1.4005396  .01320548 . 0 -163 0 1
"AAP32008" 17394  -3.281092    .3243473  .01320548 . 0 -162 0 1
"AAP32008" 17395   3.533937    2.426962  .01320548 . 0 -161 0 1
"AAP32008" 17398   4.716547  -.02697571  .01320548 . 0 -160 0 1
"AAP32008" 17399  .27063617   .10855024  .01320548 . 0 -159 0 1
"AAP32008" 17400   .9861129   1.1644855  .01320548 . 0 -158 0 1
"AAP32008" 17401  1.0941999  -.10729285  .01320548 . 0 -157 0 1
"AAP32008" 17402  2.7844026   1.1469021  .01320548 . 0 -156 0 1
"AAP32008" 17405   .5988896   -.8539982  .01320548 . 0 -155 0 1
"AAP32008" 17406  -2.650688  -2.3752906  .01320548 . 0 -154 0 1
"AAP32008" 17407   3.076281   2.1685035  .01320548 . 0 -153 0 1
"AAP32008" 17408  -1.483199   -.4189778  .01320548 . 0 -152 0 1
"AAP32008" 17409  2.1604023    1.115432 .010712328 . 0 -151 0 1
"AAP32008" 17412          0           0 .010712328 . 0 -150 0 1
end
format %td date

Much appreicated.