Hello Statalist,
I would like to create some code which can calculate various statistics (moving average, moving standard deviation, perhaps others as well) for each unit in my panel data. I will use the moving average to explain the problem. It would be fairly straightforward to calculate a moving average for each unit in the panel if I could specify a fixed period of time over which the average was to be calculated (i.e if I could say for each unit, calculate a 3 month moving average for example). However, I would like this period to vary according to the characteristics of each unit's data series in such a way that the fewer the positive, non-zero observations in the series for a given unit, the longer the period over which the average is to be taken will be. I would like to do the same for the standard deviation. The two will be calculated for the same periods within a single unit. Both calculations will be trailing.
My data is monthly. I have calculated the number of months over which the moving average should be calculated for each unit and I have generated a variable which holds this information. At the moment, I would like the number of months in the moving average to be time invariant but unit variant. Later, I may also need the period to be time variant as well so it would be extra useful if any one has a solution that is capable of integrating this additional level of flexibility.
Thank you very much for reading this, your help will be very much appreciated!
Charlie
Related Posts with Calculating Rolling Statistics for Panel Data With a Varying Window of Observation
Two questions about marginal effects (xtreg)Hello! I want to evaluate how sales of a specific product change as its price increases (due to a t…
tfdiff error messageHi everyone, I am having an issue with the command tfdiff. My data is more or less as follow: nu…
Testing Parallel Trend AssumptionI'm working on a Difference-in-Difference model. Unfortunately, I have very little experience with t…
Create rank depending on 2 variablesHey Stata Community! I have a question concerning generating a new variable. My dataset looks like…
Chow test of Structural BreakDear Statalist members, Can Chow test be performed on panel data with only one variable? I would li…
Subscribe to:
Post Comments (Atom)
0 Response to Calculating Rolling Statistics for Panel Data With a Varying Window of Observation
Post a Comment