Hello,
I have an unbalanced panel dataset where panel variable is denoted by firmid and time variable is year. I want to calculate a new variable varsalest defined as the variance of total sales (variable name is sale) in the past 5 years (t-5 to t-1) .
Going through the previous posts here, I learned to use the rolling command as below-
xtset firmid year
rolling varsales=r(Var), window(5) stepsize(5) : summarize sale, detail
I want to make sure of two things here-
1) If there are one or more missing values in the 5-year window, then the variance is calculated from the remaining values.
2) This calculation is done grouped by firm. But the 'by' prefix does not work with rolling command. How can I specify the calculation to be done by each firm?
Thanks.
I have an unbalanced panel dataset where panel variable is denoted by firmid and time variable is year. I want to calculate a new variable varsalest defined as the variance of total sales (variable name is sale) in the past 5 years (t-5 to t-1) .
Going through the previous posts here, I learned to use the rolling command as below-
xtset firmid year
rolling varsales=r(Var), window(5) stepsize(5) : summarize sale, detail
I want to make sure of two things here-
1) If there are one or more missing values in the 5-year window, then the variance is calculated from the remaining values.
2) This calculation is done grouped by firm. But the 'by' prefix does not work with rolling command. How can I specify the calculation to be done by each firm?
Thanks.
Comment