Hi,
I have followed Clyde's code here to input variance and eventually standard deviation in my data:
Code:
// CALCULATE SOME RUNNING TOTALS OF RET AND RET^2*
by company_id (bcal_date), sort: gen sum_ret = sum(return)
by company_id (bcal_date): gen sum_ret_sq = sum(return^2)
// AND A RUNNING COUNT OF NON MISSING OBSERVATIONS*
by company_id (bcal_date): gen int n_obs = sum(!missing(return))
sort company_id bcal_date
// NOW CALCULATE RUNNING STANDARD DEVIATIONS
gen variance = (L1.sum_ret_sq - L3047.sum_ret_sq)/(L1.n_obs-L3047.n_obs)-((L1.sum_ret - L3047.sum_ret)/(L1.n_obs-L3047.n_obs))^2
gen sd = sqrt(variance)
However, I cannot seem to get the L1 numbers correct. I am unsure which number to place here, I used the largest value of n_obs, which is 3047 for me, but it does not work. Anyone have any advice? It would be much appreciated!
I have followed Clyde's code here to input variance and eventually standard deviation in my data:
Code:
// CALCULATE SOME RUNNING TOTALS OF RET AND RET^2*
by company_id (bcal_date), sort: gen sum_ret = sum(return)
by company_id (bcal_date): gen sum_ret_sq = sum(return^2)
// AND A RUNNING COUNT OF NON MISSING OBSERVATIONS*
by company_id (bcal_date): gen int n_obs = sum(!missing(return))
sort company_id bcal_date
// NOW CALCULATE RUNNING STANDARD DEVIATIONS
gen variance = (L1.sum_ret_sq - L3047.sum_ret_sq)/(L1.n_obs-L3047.n_obs)-((L1.sum_ret - L3047.sum_ret)/(L1.n_obs-L3047.n_obs))^2
gen sd = sqrt(variance)
However, I cannot seem to get the L1 numbers correct. I am unsure which number to place here, I used the largest value of n_obs, which is 3047 for me, but it does not work. Anyone have any advice? It would be much appreciated!
Comment