Hello everyone,
I'm currently facing an issue with my code, and I need some assistance. I have a dataset that contains daily returns of 136 mutual funds and 5 Fama-French factors over a span of 23 years. My objective is to run a looped regression for each fund, regressing it on the 5 Fama-French factors. Afterwards, I want to calculate the average coefficients, standard errors, and t-tests for the constant and the Fama-French factors. Essentially, I aim to obtain the same output as a regular regression, but for the average of looped regressions.
The following code represents my loop, which is currently working successfully:
However, I'm encountering issues when attempting to store the coefficients in a matrix for calculating the averages. I've tried the following code, but it is not working, and I'm unsure about what's causing the problem:
I would greatly appreciate any help and advice regarding this issue. Thank you in advance for your assistance!
I'm currently facing an issue with my code, and I need some assistance. I have a dataset that contains daily returns of 136 mutual funds and 5 Fama-French factors over a span of 23 years. My objective is to run a looped regression for each fund, regressing it on the 5 Fama-French factors. Afterwards, I want to calculate the average coefficients, standard errors, and t-tests for the constant and the Fama-French factors. Essentially, I aim to obtain the same output as a regular regression, but for the average of looped regressions.
The following code represents my loop, which is currently working successfully:
Code:
local num_funds = 136 local start_col = 2 local end_col = 137 local coef_start_col = 138 local coef_end_col = 142 foreach fund of numlist `start_col'/`end_col' { local dep_var = "m" + string(`fund' - `start_col' + 1) regress `dep_var' MktRF SMB HML RMW CMA }
Code:
local num_funds = 136 local start_col = 2 local end_col = 137 local coef_start_col = 138 local coef_end_col = 142 matrix coef_matrix = J(`num_funds', `coef_end_col' - `coef_start_col' + 1, .) // Create a new matrix to store the coefficients foreach fund of numlist `start_col'/`end_col' { local dep_var = "m" + string(`fund' - `start_col' + 1) regress `dep_var' MktRF SMB HML RMW CMA matrix coef_vector = e(b) local row = `fund' - `start_col' + 1 forval i = 1/(`coef_end_col' - `coef_start_col' + 1) { local col = `i' matrix coef_matrix[`row', `col'] = coef_vector[1, `coef_start_col' + `i' - 1] } } egen mean_results = rowmean(results) egen se_results = rowstd(results) / sqrt(`num_funds') matrix list mean_results matrix list se_results
I would greatly appreciate any help and advice regarding this issue. Thank you in advance for your assistance!
Comment