Dear Statalisters,
My panel dataset is by firm/year/month with monthly stock returns between 1975 to 2012. I need to construct the return volatility using standard deviation of monthly return over the past two years. My sample data is given below. I did not show the whole past three years to conserve space.
input str4 firmid year month ret
1001 1990 1 0.01
1001 1990 2 -0.2
1001 1990 3 0.3
1001 1990 4 0.01
1001 1990 5 0.03
1001 1990 6 0.05
1001 1990 7 0.3
1001 1990 8 0.1
1001 1990 9 -0.05
1001 1990 10 0.05
1001 1990 11 0.1
1001 1990 12 0.4
1001 1991 1 .
1001 1991 2 0.1
1001 1991 3 0.3
1001 1991 4 0.05
1001 1991 5 0.3
1001 1991 6 0.001
1001 1991 7 0.002
1001 1991 8 0.005
1001 1991 9 0.04
1001 1991 10 0.009
1001 1991 11 -0.001
1001 1991 12 -0.003
end
My question is: how to generate this stdev variables for firm 1001 in year 1992, using data from 1990 to 1991, then stdev in year 1993, using data from 1991-1992, and so on.
Thank you,
Rochelle
My panel dataset is by firm/year/month with monthly stock returns between 1975 to 2012. I need to construct the return volatility using standard deviation of monthly return over the past two years. My sample data is given below. I did not show the whole past three years to conserve space.
input str4 firmid year month ret
1001 1990 1 0.01
1001 1990 2 -0.2
1001 1990 3 0.3
1001 1990 4 0.01
1001 1990 5 0.03
1001 1990 6 0.05
1001 1990 7 0.3
1001 1990 8 0.1
1001 1990 9 -0.05
1001 1990 10 0.05
1001 1990 11 0.1
1001 1990 12 0.4
1001 1991 1 .
1001 1991 2 0.1
1001 1991 3 0.3
1001 1991 4 0.05
1001 1991 5 0.3
1001 1991 6 0.001
1001 1991 7 0.002
1001 1991 8 0.005
1001 1991 9 0.04
1001 1991 10 0.009
1001 1991 11 -0.001
1001 1991 12 -0.003
end
My question is: how to generate this stdev variables for firm 1001 in year 1992, using data from 1990 to 1991, then stdev in year 1993, using data from 1991-1992, and so on.
Thank you,
Rochelle
Comment