Announcement

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

  • Matching two datasets

    Hi,

    I have one dataset with 33 observations where I have three geographical variables:

    state which is the largest one,
    region- the second largest
    district - the smallest union,



    e.g the dataset looks like this:

    state )region district

    Arunachal Pradesh. Arunachal East East Slag
    Arunachal Pradesh Arunachal East lohit
    Arunachal Pradesh Arunachal East trap
    Arunachal Pradesh Arunachal West East Kameng
    Arunachal Pradesh Arunachal West Lower Subansiri



    The second dataset, individual level, I have 321 observations, with the name of the people coming from each state and regions, say. The same name is very rarely happening more than once in the second data, e.g means it is not very often found in more than one region.

    state region
    Arunachal Pradesh. Arunachal East KASHME LINGI
    Arunachal Pradesh Arunachal East. WANGCHA RAJKUMAR
    Arunachal Pradesh Arunachal West PREM KHANDU THUNGON


    What I want to have is for each of the name that is present in the second dataset to be matched to each of the districts from the first data, irrespective if that name appears for all regions in the second data or not e.g. the name KASHME LINGI appears in Arunachal Pradesh. state and Arunachal East region , but I want it to be matched to all the districts of the state Arunachal Pradesh, so I want my data to look like this



    state )region district name

    Arunachal Pradesh. Arunachal East East Slag KASHME LINGI
    Arunachal Pradesh Arunachal East lohit KASHME LINGI
    Arunachal Pradesh Arunachal East trap KASHME LINGI
    Arunachal Pradesh Arunachal West East Kameng KASHME LINGI
    Arunachal Pradesh Arunachal West Lower Subansiri KASHME LINGI



    Similarly, for the rest of the names. Merge command , doesn't work. Can you please let. me know how to proceed?

    Many thanks,
    Ciara








  • #2
    For those of us not familiar with your local geography, we cannot tell where the names of the states end and the names of the regions begin, which makes it difficult to understand the layout of your data. Please read the Forum FAQ, with particular attention to #12. The helpful way to show example data is by using the -dataex- command. 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..

    Another thing you will learn from reading the Forum FAQ is that it is useless to say something "doesn't work." What does that mean? Did you get an error message? If so, which one? If not, what happened: it ran but you got results you didn't expect? What were those results? Why were they different from what you expected? Or did Stata crash? Or what?

    Also, you don't show the actual -merge- command you used that "doesn't work." So we can't tell if you simply coded it incorrectly, or if perhaps this isn't a job for -merge- in the first place.

    The more information you give to those who want to help you, the more likely it is they will be able to do so.

    Comment

    Working...
    X