Announcement

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

  • Summing data by year and country

    Good evening,

    I have data that looks sort of like this example:
    Year Host Country Origin Country Refugees
    2000 Afghanistan Lebanon 20
    2000 Afghanistan Syria 30
    2001 Afghanistan Lebanon 40
    2001 Afghanistan Syria 60
    2001 Afghanistan Palestine 20
    2000 Germany Albania 5
    2000 Germany Algeria 10
    2000 Germany Syria 50
    Etc. for a dataset with thousands of rows of countries and years.


    And i would like to remove the distinction of the origin countries so that the refugees are added up like so (using the example):
    Year Host Country Refugees total
    2000 Afghanistan 50
    2001 Afghanistan 120
    2000 Germany 65
    Are there any commands i could use to combine the refugee data per year/host-country group?

  • #2
    Code:
    collapse (sum) refugees, by(host_country year)
    -collapse- is one of the "bread and butter" commands in Stata that everyone needs to know about to use Stata effectively. I suggest reading the Getting Started [GS] and User's Guide [U] volumes of the PDF manuals that come with your Stata installation in their entirety. While you won't remember everything, they will introduce you to the basic commands that are commonly used and familiarize you with Stata's general approach to data management and analysis. With that time invested, you will in most situations grasp which commands are likely to figure in the solution to your problem, and then you can refer to the help files for the unremembered details of syntax.

    In the future, before posting example data, import it to Stata, and then use the -dataex- command to post it. You can get the -dataex- command by running -ssc install dataex-, and you can read the simple instructions for using it by running -help dataex-. Using -dataex- to post example data makes it possible for those who want to help you to create a faithful replica of your Stata example with a simple copy/paste operation.

    Comment


    • #3
      Thank you! This solved my problem. I knew of the collapse function but i didn't fully understand i could use it like that. Learned something new today.
      I'll take your advice and look more into the bread and butter commands of Stata.

      Comment

      Working...
      X