Announcement

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

  • Means

    Dear All

    I have data on GDP (var= gdp) for different countries (var = iso) , for different years (var=year). My data is in long view. I would like to generate a new variable that calculates the average GDP over the proceeding 10 years for each year for each country. I know i need egen and by sort, but am struggling! Any help would be much appreciated!

    Many Thanks

    Joe

  • #2
    Many threads can be found here on such problems with a little searching.

    egen could be used, but I think you'd need to install user-written functions to make easy headway.

    A more general approach would be based on installing tsegen (SSC). Notional example:

    Code:
    webuse grunfeld
    
    xtset company year
    
    tsegen invest10 = rowmean(L(1/10).invest)
    
    edit company year invest*
    That calculation uses whatever data are available, even single values. See also the help.

    See original thread at http://www.statalist.org/forums/foru...egen-functions and if needed search for further mentions.
    Last edited by Nick Cox; 30 Dec 2015, 08:51.

    Comment


    • #3
      Hi Nick
      Thank you so much for your quick reply. Looking at your example it seems this is what I need, but it still doesn't work with my data, as there are repeated time values within the panel; each country has mortality data for each year, for each age group within each year and finally for each sex within each age group. For each mortality observation, I need the corresponding mean gdp from the previous 10 years - I hope that makes sense. Here is an example:

      country year ****age **sex ****mortality** gdp
      a *******1990**** 1**** m******** 6 *******10
      a *******1990**** 1**** f *********5 *******10
      a *******1990**** 2 ****m******** 2******* 10
      a *******1990**** 2**** f **********4 *******10
      a *******1991**** 1**** m********* 8******* 12
      a *******1991**** 1**** f **********7******* 12
      a *******1991**** 2**** m *********3******* 12
      a *******1991**** 2**** f **********4******* 12

      (sorry about the stars, its the only way I could draw the table!)

      Any help would be much appreciated!

      Best Wishes

      Joe
      Last edited by Joe Ward; 30 Dec 2015, 09:36.

      Comment


      • #4
        That sounds much more complicated than what you originally stated. My guess is that, instead of using country as the ID variable, you need to create a new id variable for each unique combination of country/age/sex/ etc. Or something like that.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Hello
          thank you again for your help - Ive worked out a way of doing it. I had merged the gdp data (which just has one observation per year per country) with the mortality data. I just used your code to get my 10 year gdp average on the original data set, then merged it with the mortality data - I think it worked!
          Thank you

          Comment

          Working...
          X