Hello Everyone,
I am having some trouble in understanding the D1. command.
I currently have a dataset with daily values of the S&P500 (from 1/1/190 to 12/31/2014) and I would like to calculate the compounded returns (which is the diff in log prices from t to t-1). My data do not have saturdays, sundays and holidays (in other words, my data have gaps).
date s&P500
1/1/1990 1
1/2/1990 2
....
12/31/2014 4
At first I got the log(s&p500 variable). Now have 2 options (let's call the s&p500, x):
1) gen lag_log_x= log_x[_n-1]
generate return_x= log_x - lag_log_x
This will work ok
2) tsset date, daily
tsfill //*no gaps now*//
gen lag_log_x=L1. log_x
gen return_x=D1. log_x
In theory these two methodologies should give me the same results, but they don't!!! The second approach deletes my monday observation (reducing the number of observations to 4 for week instead of 5).
Even if I compute the second approach without filling the gaps, STATA still deletes my monday observation (I don't get it!)
Can anyone help me in understanding how I can solve this problem? I don't want to lose observations.
Thank you
Buffy
I am having some trouble in understanding the D1. command.
I currently have a dataset with daily values of the S&P500 (from 1/1/190 to 12/31/2014) and I would like to calculate the compounded returns (which is the diff in log prices from t to t-1). My data do not have saturdays, sundays and holidays (in other words, my data have gaps).
date s&P500
1/1/1990 1
1/2/1990 2
....
12/31/2014 4
At first I got the log(s&p500 variable). Now have 2 options (let's call the s&p500, x):
1) gen lag_log_x= log_x[_n-1]
generate return_x= log_x - lag_log_x
This will work ok
2) tsset date, daily
tsfill //*no gaps now*//
gen lag_log_x=L1. log_x
gen return_x=D1. log_x
In theory these two methodologies should give me the same results, but they don't!!! The second approach deletes my monday observation (reducing the number of observations to 4 for week instead of 5).
Even if I compute the second approach without filling the gaps, STATA still deletes my monday observation (I don't get it!)
Can anyone help me in understanding how I can solve this problem? I don't want to lose observations.
Thank you
Buffy
Comment