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
Keep with conditionHey guys, I want to keep only the observations which are untimely by the employee and at the same ti…
Graphing Interaction of Time-Varying Covariate and Dummy Variable in a Growth Curve Model using MIxedGreetings. I have a longitudinal data set (set up in long form), and I am trying to graph a signific…
After estimation, how can I obtain predictions at the mean of some of the covariates?I know that after estimation if I replace some of the covariates with their means and predict, I can…
Multicollinearity after variable transformation & impact on R^2Hello, I am running a simple linear regression model and I found that 3 of my variables (ssr1 ssr2 …
Standard deviation lines for xtline graphI am wondering how to add standard deviation lines to a timeseries graph I made (xtline) I calculat…
Subscribe to:
Post Comments (Atom)
0 Response to Calculating Rolling Statistics for Panel Data With a Varying Window of Observation
Post a Comment