Announcement

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

  • Average for a variable and over a time period

    Hey guys, I'm a Stata beginner and stuck on an issue. I'm using a cross-country and time panel data set. I'm trying to take the average (over the 15 year time period) for each country of a variable. Can someone please share the easiest way to accomplish this? For example, I have sub-Saharan countries (unit_id), over the time period (year), and variables (e.g. aid, conflict).

    Any help would be really appreciated!

    Thanks,
    Gina

  • #2
    Hi Georgina,

    Welcome on board.

    You can use the collapse function...

    Code:
    preserve 
    collapse (mean) aid conflict, by(unit_id)
    table aid conflict, by(unit_id)
    Make sure to use the -preserve- command to be able to get your data again in their original format.

    Good luck!
    Best,
    Maye

    Comment


    • #3
      Alternatively, -egen- will get you the averages without needing to discard cases. This way you could use your country-averages in further analyses without any extra steps like merging them back onto the original data..

      Code:
      sort unit_id
      egen meanaid=mean(aid), by(unit_id)

      Comment


      • #4
        Thank you Maye and Ben! I ended up using the generate mean, by function!

        Comment

        Working...
        X