Announcement

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

  • Replacing observations in panel data

    Dear all,

    I am new to Stata and basic tasks that can be done in Excel within seconds take too much time due to my limited knowledge.

    Here is my question: How can I generate a new region in the below sample dataset named "North America" which consists of the total values of the USA and Canada? In other words, the 2015 value of "North America" will be 95, 2016 will be 100, and so on.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 region int year byte value
    "South America"  2015 10
    "South America"  2016 12
    "South America"  2017 15
    "South America"  2018 18
    "South America"  2019 20
    "South America"  2020 25
    "Western Europe" 2015 24
    "Western Europe" 2016 25
    "Western Europe" 2017 26
    "Western Europe" 2018 28
    "Western Europe" 2019 30
    "Western Europe" 2020 27
    "Eastern Europe" 2015 33
    "Eastern Europe" 2016 35
    "Eastern Europe" 2017 36
    "Eastern Europe" 2018 40
    "Eastern Europe" 2019 50
    "Eastern Europe" 2020 48
    "USA"            2015 50
    "USA"            2016 54
    "USA"            2017 56
    "USA"            2018 60
    "USA"            2019 66
    "USA"            2020 60
    "Canada"         2015 45
    "Canada"         2016 46
    "Canada"         2017 48
    "Canada"         2018 51
    "Canada"         2019 56
    "Canada"         2020 52
    end
    Thanks.
    Last edited by John Pax; 15 Jan 2024, 14:02.

  • #2
    Code:
    replace region = "North America" if inlist(region, "USA", "Canada")
    collapse (sum) value, by(region year)
    There are many resources available to help you become efficient in the use of the basic commands in Stata. You can start with the manual that is installed with your Stata. Read the Getting Started [GS] and User's Guide [U] sections to learn the commands that every Stata user needs to know. You can then progress farther by availing yourself of other helpful materials. For example, the Stata online webcourses are very well done and, for me, were enormously helpful when I was a beginner. The StataCorp bookstore also has a number of books that are aimed at beginners--you can peruse them and perhaps pick one that seems compatible with your learning style and needs.

    Comment


    • #3
      Thanks a lot, Clyde. Appreciated!

      Comment

      Working...
      X