Announcement

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

  • Regarding generating year-sum for each variable

    Dear,

    I have a question.

    I have a panel data looks like below.

    Code:
    country  year   x     y
    "Indonesia" 1990  24   36
    "Indonesia" 1991  28   22
    "Korea"       1990  38   27
    "Korea"       1991  42   73
    "China"       1990  124 458
    "China"       1991  12   24

    I'd like to generate sum for each year of each variable from 1990 to 2014 and want to plot them.
    Would you help me to do these?

    Many Thanks,
    Last edited by Woosung Kim; 26 Jan 2022, 16:15.

  • #2
    Code:
    collapse (sum) x y, by(year)
    graph twoway line x y year, sort

    Comment


    • #3
      Thanks a lot. It helps me.
      Best,

      Comment


      • #4
        You could also go

        Code:
        egen sum_x = total(x), by(year)
        egen tag = tag(year)
        line sum_x year if tag, sort
        and similarly for other variables.

        Comment

        Working...
        X