Hi,
I did a loop regression and now want to compute a t-test only on the constants being calculated. My current code is calculating the t-test over the whole data set. Any help?
I did a loop regression and now want to compute a t-test only on the constants being calculated. My current code is calculating the t-test over the whole data set. Any help?
Code:
use "Data - RLBOS Stock and FF Master1.dta", clear
merge m:m DataDate using "Benchmark Daily.dta"
drop if _merge == 1 | _merge == 2
drop _merge
sort GVKEY DataDate DateCompletedIssue
bys GVKEY seconddate: egen benchmarkyrret = mean(ValWeightRet)
sort GVKEY DataDate
by GVKEY (DataDate): gen dealexcessreturns = monthlyreturn - benchmarkyrret
bys GVKEY seconddate: egen marketexcessreturns = mean(mktrf)
sort GVKEY
egen group_id = group(GVKEY)
** Run the CAPM regression for the first group range
encode GVKEY, gen(GVKEY_num)
estimates clear
levelsof GVKEY_num, local(groups)
local start_group1 1
local end_group1 88
scalar sum_alpha1 = 0 // Initialize a sum variable for alpha1
scalar count_alpha1 = 0 // Initialize a count variable for alpha1
local constants = 0
bysort GVKEY seconddate: keep if _n==1
bysort GVKEY: drop if _n==1
gen alpha_values = .
foreach group of local groups {
if `group' >= `start_group1' & `group' <= `end_group1' {
regress dealexcessreturns marketexcessreturns if GVKEY_num == `group', robust
estimates store capm_`group'
scalar alpha1 = _b[_cons] - (rf + benchmarkyrret * marketexcessreturns)
display "`group' alpha1: " alpha1
replace alpha_values = alpha1 if GVKEY_num == `group'
// Update the sum and count for alpha1
scalar sum_alpha1 = sum_alpha1 + alpha1
scalar count_alpha1 = count_alpha1 + 1
}
}
scalar constants = sum_alpha1 / count_alpha1
ttest alpha_values = 0 if !missing(alpha_values)
signrank alpha_value = 0
