Announcement

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

  • Panel data: yearly average only for certain countries

    Dear Stata users,

    I have panel data for 32 countries from 1990-2012.

    I used this code to create averages so I get a graph with the development for the greenhouse gas emissions.

    Code:
    bysort year: egen average_GHG = mean(GHG)
    However, I want to create an if condition so I can look at the development of the average greenhouse gas emissions for a smaller set of countries per year.

    I tried:

    Code:
    bysort year: egen average_GHG = mean(GHG) if inlist(countryid, 4, 24, 14, 15, 6, 26)
    But this does not seem to work.

    Thank you in advance!

  • #2
    Hi lulan lulan , maybe something like this:
    Code:
    gen small=(countryid==4 | countryid==24 | countryid==14 | countryid==15 | countryid==6 | countryid==26)
    bysort year: egen average_GHG = mean(GHG) if small==1
    Last edited by Daniel PV; 14 May 2022, 08:53.

    Comment


    • #3
      But this does not seem to work.
      Quoting from the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post:

      12.1 What to say about your commands and your problem

      Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
      ...
      Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.

      Comment


      • #4
        Originally posted by Daniel PV View Post
        Hi lulan lulan , maybe something like this:
        Code:
        gen small=(countryid==4 | countryid==24 | countryid==14 | countryid==15 | countryid==6 | countryid==26)
        bysort year: egen average_GHG = mean(GHG) if small==1
        This worked! Thank you

        Comment


        • #5
          #2 should be the same in implication as #1, so far as I can see, so whatever the problem was will have been something else.

          Comment

          Working...
          X