Hi there,
I am desperately looking for a way to estimate the alpha and the betas of the carhart 4 factor model.
I need a code which makes a regression between the return of a stock and 4 global factors influencing the whole market. These correlation coefficients of the estimation window are the betas to calculate the expected return in the event window. My data set contains more than 1000 different stocks, and looks like following:
days return of the stock mktrf smb hml umd intercept b_mktrf b_smb b_hml b_umd
-200 0.012 0.0012 0.054 0.065 0.007 ? ? ? ? ?
-199 .. ... ... .. ..
...
-52
...
0
1
2
..
I need to estimate the "?" now. The Estimation Window is always <-51 and >-200, the event window 0,1.
I have tried various way, but always failed, this is my closest try, but STATA just does not come to an end calculating:
sort group_id date
by group_id : gen datenum=_n
by group_id: gen dif= date- ceo_turnover_date
by group_id: gen dif1= ((dif)^2)^0.5
by group_id : egen min_dif1=min(dif1)
by group_id : gen target=datenum if dif1==min_dif1
egen td=min(target), by( group_id )
gen dif2=datenum-td
by group_id : gen event_window=1 if dif2>=-2 & dif2<=2 & ret!=. & vwretd!=.
egen count_event_obs=count(event_window), by( group_id )
by group_id : gen estimation_window=1 if dif2<-51 & dif2>=-200 & ret!=. & vwretd!=.
egen count_est_obs=count(estimation_window), by( group_id )
replace event_window=0 if event_window==.
replace estimation_window=0 if estimation_window==.
drop if count_event_obs < 5
drop if count_est_obs < 149
gen alpha = .
gen b_mktrf = .
gen b_smb = .
gen b_hml = .
gen b_umd = .
gen return_minus_rf= ret-rf
gen predicted_return=.
egen id_estimation=group(group_id)
sort group_id date
sum id_estimation
rename return_minus_rf excess_return_interlcompany
qui forval p = 1/`=_N' {
l id_estimation group_id if id_estimation==`p' & dif2==0
capture bygroup: reg excess_return_interlcompany mktrf smb hml umd if id_estimation ==`p' & estimation_window==1
capture replace alpha = _b[_cons] in `p'
capture replace b_mktrf = _b[mktrf] in `p'
capture replace b_smb = _b[smb] in `p'
capture replace b_hml = _b[hml] in `p'
capture replace b_umd = _b[umd] in `p'
}
Is anyone able to offer me any help?
I am desperately looking for a way to estimate the alpha and the betas of the carhart 4 factor model.
I need a code which makes a regression between the return of a stock and 4 global factors influencing the whole market. These correlation coefficients of the estimation window are the betas to calculate the expected return in the event window. My data set contains more than 1000 different stocks, and looks like following:
days return of the stock mktrf smb hml umd intercept b_mktrf b_smb b_hml b_umd
-200 0.012 0.0012 0.054 0.065 0.007 ? ? ? ? ?
-199 .. ... ... .. ..
...
-52
...
0
1
2
..
I need to estimate the "?" now. The Estimation Window is always <-51 and >-200, the event window 0,1.
I have tried various way, but always failed, this is my closest try, but STATA just does not come to an end calculating:
sort group_id date
by group_id : gen datenum=_n
by group_id: gen dif= date- ceo_turnover_date
by group_id: gen dif1= ((dif)^2)^0.5
by group_id : egen min_dif1=min(dif1)
by group_id : gen target=datenum if dif1==min_dif1
egen td=min(target), by( group_id )
gen dif2=datenum-td
by group_id : gen event_window=1 if dif2>=-2 & dif2<=2 & ret!=. & vwretd!=.
egen count_event_obs=count(event_window), by( group_id )
by group_id : gen estimation_window=1 if dif2<-51 & dif2>=-200 & ret!=. & vwretd!=.
egen count_est_obs=count(estimation_window), by( group_id )
replace event_window=0 if event_window==.
replace estimation_window=0 if estimation_window==.
drop if count_event_obs < 5
drop if count_est_obs < 149
gen alpha = .
gen b_mktrf = .
gen b_smb = .
gen b_hml = .
gen b_umd = .
gen return_minus_rf= ret-rf
gen predicted_return=.
egen id_estimation=group(group_id)
sort group_id date
sum id_estimation
rename return_minus_rf excess_return_interlcompany
qui forval p = 1/`=_N' {
l id_estimation group_id if id_estimation==`p' & dif2==0
capture bygroup: reg excess_return_interlcompany mktrf smb hml umd if id_estimation ==`p' & estimation_window==1
capture replace alpha = _b[_cons] in `p'
capture replace b_mktrf = _b[mktrf] in `p'
capture replace b_smb = _b[smb] in `p'
capture replace b_hml = _b[hml] in `p'
capture replace b_umd = _b[umd] in `p'
}
Is anyone able to offer me any help?
Comment