Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • problems with moving average - panel data

    Hi everyone,
    I am using Italian administrative longitudinal data for 10 years. Since I would like to understand how household income has evolved in my dataset over time, I thought to resort to the Moving Average. My Idea was therefore to take the average household income in each year and then generating the MA. However, I have a lot of problems. I am not able to use the AC function, even if I have installed the user-created command "PANELAUTO". Furthermore, when I use the tsgraph, nothing appears in the graph. Is there anyone who could help me?
    I post here an example of the dataset at my disposal:

    Code:
    input long ID str8 ID_hh float(year hh_income)
    1 "01" 2006 16590.01
    1 "01" 2007 17380.10
    1 "01" 2008 17600.91
    1 "01" 2009 18111.36
    1 "01" 2010 20217.31
    1 "01" 2011 20300.63
    1 "01" 2012 23567.38
    1 "01" 2013 22698.79
    1 "01" 2014 23009.00
    1 "01" 2015 23090.34
    1 "01" 2016 23250.55
    2 "01" 2006 16590.01
    2 "01" 2007 17380.10
    2 "01" 2008 17600.91
    2 "01" 2009 18111.36
    2 "01" 2010 20217.31
    2 "01" 2011 20300.63
    2 "01" 2012 23567.38
    3 "02" 2008 28656.31
    3 "02" 2009 29360.20
    3 "02" 2010 26003.27
    3 "02" 2011 25322.36
    3 "02" 2012 25210.16
    3 "02" 2013 24200.56
    3 "02" 2014 25300.36
    
    end
    Where ID is individual's idenitfier, ID_hh is household identifier, and hh_income is household income (per year)
    Thank you a lot in advance,
    Andrea

  • #2
    You didn't get a quick answer. You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex. Without this information (e.g., exactly what you ran), we have no way to help you with vague problems like "tsgraph, nothing appears in the graph".

    Almost always, the first thing to do is to xtset such data with ID as the panel and year as the time. If you say exactly what you want to calculate, we can help you. With community contributed programs, it is quite possible that none of the active folks have used the routine.

    If all you want is to average over time, after xtset, you can just calculate the average:
    g ave3=(hh_income + L.hh_income + L2.hh_income)/3

    Whether a moving average is actually a good idea would depend heavily on your model - it often creates complex artificial relations in the data since the same underlying observation appears in more than one moving average observation. However, if you're talking about moving average estimators, some time series estimators in Stata do not work with panel data. I don't now about

    Comment


    • #3
      Thank you Phil for your answer. I am trying to create measures of income shocks. I thought to resort to the moving average and the code I wrote is:
      Code:
      xtset ID year
      egen mean_hh_income = mean(hh_income), by (year) 
      tssmooth ma ma1 = mean_hh_income, window(2 1)
      generate noise = mean_hh_income - ma1
      ac noise
      tsgraph ma1 year
      I managed to create the moving average, however when I try to plot the noise using "ac" I get "sample may not include multiple panels" (error r(459)). When I instead use tsgraph, I get an empty graph. I do not understand what is going on. This is probably due to the fact that I am quite new on Stata and I have never used time series on it.
      Thank you in advance,
      Andrea

      Comment

      Working...
      X