Announcement

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

  • Individuals within countries panel data

    Good morning fellow statalisters. I just have a quick question:

    I currently have a dataset with multiple observations (individual responses) for multiple countries in multiple years. Now, when trying to xtset it I receive the r(451) error code which I expect given that I have repeating values of country/time. However, what I am trying to achieve is a panel data specification for individuals in a given country at time t. Would anyone be able to offer any assistance regarding how I'd go about attaining such a specification. I've tried collapsing the data set however for variables such as gender that don't vary over time this computes an mean of each of these for each country...

    Thanks in advance!

  • #2
    You do not show any example data, and from your description I am not certain how your data are actually organized. I'm going to guess that each observation corresponds to a single person, and that there are variables person_id, country, and year. The variable person_id may refer to different people when used in different countries (person nested within country), but for any given country, all references to a value of person_id refer to the same person. If that's not right, post back using the -dataex- command to show example data and explain the organization in more detail. If that is right:

    Code:
    egen distinct_person_id = group(person_id country)
    xtset distinct_person_id year
    If you are running version 15.1 or a fully updated version 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.



    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment

    Working...
    X