My data is an unbalanced panel data.
id: wficn (to uniquely identify each mutual fund)
yrqt: the time variable, such as 1998q1,1998q2,1998q3,...etc.
and key variable:
x: fund style characteristics, x has many missings, the values of x range from 1 to 5.
What I want to do is to calculate the standard deviation of variable x for past 12 quarters, call the new variable std_x
in order to make the standard deviation not noisy, I need to require that for each fund, quarter, it has non-missing x for the past 12 quarters,
for those that have missings, I will not calculate the vales for std_x, I just let it be missing too.
say, for example, for fund i, for quarter 2000q1, for past 12 quarters, it has only 2 (<12) non-missing x, I will not use that two non-missing values to calculate the standard deviation for x, I will let std_x be missing too.
My question is how to calculate this standard deviation?
id: wficn (to uniquely identify each mutual fund)
yrqt: the time variable, such as 1998q1,1998q2,1998q3,...etc.
and key variable:
x: fund style characteristics, x has many missings, the values of x range from 1 to 5.
What I want to do is to calculate the standard deviation of variable x for past 12 quarters, call the new variable std_x
in order to make the standard deviation not noisy, I need to require that for each fund, quarter, it has non-missing x for the past 12 quarters,
for those that have missings, I will not calculate the vales for std_x, I just let it be missing too.
say, for example, for fund i, for quarter 2000q1, for past 12 quarters, it has only 2 (<12) non-missing x, I will not use that two non-missing values to calculate the standard deviation for x, I will let std_x be missing too.
wficn | yrqt | x | std_x | |
0001 | 1998q1 | 1 | . | |
0001 | 1998q2 | 2 | . | |
0001 | 1998q3 | 3 | . | |
0001 | 1998q4 | 2 | . | |
0001 | 1999q1 | 1 | . | |
0001 | 1999q2 | 2 | . | |
0001 | 1999q3 | 1 | . | |
0001 | 1999q4 | 2 | . | |
0001 | 2000q1 | 2 | . | |
0001 | 2000q2 | 1 | . | |
0001 | 2000q3 | 2 | . | |
0001 | 2000q4 | 2 | . | |
0001 | 2001q1 | 2 | some number | |
0001 | 2001q2 | . | . | |
0001 | 2001q3 | 1 | . | |
0001 | 2001q4 | 2 | . | |
0001 | 2002q1 | . | . | |
0001 | 2002q2 | 3 | . | |
0001 | 2002q3 | 4 | . |
Comment