Announcement

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

  • collapsing or transforming year data into decades

    Hi,
    Is there a simple way to collapse a dataset or simply plot a graph from yearly data into decade data/ I want to smooth out conflict data from 1875-2000 in terms of proportions per ten year block, but can't seem to find how to transform my data or how to plot.

    BTW, I'm relatively new to Stata, just getting too frustrated in R

    DAvid

  • #2
    Given a variable

    Code:
     
    gen decade = 10 * floor(year/10)
    you can collapse or contract as desired.

    Comment


    • #3
      Nick,
      Thank you, I figured it was something like this. I don't know the function floor()...thanks.

      How would I set the baseline at 1870-80, 80-90, onwards?

      cheers
      David

      Comment


      • #4
        I don't know what that means precisely. I don't suppose you want to include 1880 twice, and so on, but I don't know how your definition differs from what my code does.

        Comment


        • #5
          May I add a little clarification. Nick's code is to generate decade identifiers. You could do the same thing much less efficiently with a bunch of conditional statements.
          g decade=1890 if year>1889 & year <1900
          replace decade=1900 if year>1999 & year <1910
          etc.

          When you say you want to use 10 year blocks, this could be interpreted several ways. You might mean you want rolling 10 year averages so you still have almost the same number of observations as the original data but replace the value of x in year t with the mean of x from t-5 to t+4 or some such. While I'm sure there is a more efficient way to do this, if you have set the time variable, you can simply do something like:

          g smoothx=(L4.x + L3.x + L2.x + L1.x + x + F1.x + F2.x + F3.x + F4.x)/9

          Alternatively, you might want to simply move to decade data so you have one observation for each decade.

          It you want to move to decade data, having created the decade identifier, you then use collapse to move from yearly data to decade data. Collapse will let you collapse using a variety of different statistics (e.g., mean or median or percentiles or whatever).



          Phil




          Comment

          Working...
          X