Announcement

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

  • Sum of population

    Good day. Please may you assist with syntax on how I can obtain total population for each of the areas (1, 2) for each year.

    The data is presented as follows:
    SA2 Year Population Area
    123 2019 200 1
    123 2020 250 1
    149 2019 300 1
    149 2020 320 1
    149 2020 320 1
    149 2021 350 1
    201 2019 50 2
    201 2020 100 2
    202 2020 120 2
    202 2021 130 2

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int(sa2 year population) byte area
    123 2019 200 1
    123 2020 250 1
    149 2019 300 1
    149 2020 320 1
    149 2020 320 1
    149 2021 350 1
    201 2019  50 2
    201 2020 100 2
    202 2020 120 2
    202 2021 130 2
    end
    
    by area year, sort: egen total_population = total(population)
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.


    Comment


    • #3
      If you just want to see the stats, then

      Code:
      tabstat population if year==2019, by(area) stats(sum)

      Comment


      • #4
        Apologies, I should have been more specific about the question. I would like the syntax to create the derived variable: Total population for each year for each area. I will remember to use dataex next time. Thanks

        Comment


        • #5
          I have just seen the syntax. Thanks Clyde and thanks George for the tabulation

          Comment

          Working...
          X