Announcement

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

  • Linking 2 variables

    I am new to STATA. I am looking for help on linking 2 variables in the same dataset. The dataset is similar to a census data. (Specifically its UK's understanding society dataset)
    I have the below variables
    a= person identifier
    b= person's education level
    c= persons wellbeing
    p2= partner number

    I am trying to run a regression with person's wellbeing related to partner's education level.
    How do I link these 2 variables?

    There is no direct value in the table for partner's education level.

    So I need to link a-> p2 ->b

  • #2
    I'm going to assume that your "partner number" p2 means the value of the person identifier (variable a) that appears in the current person's partner's observation.

    Code:
    use dataset, clear
    
    // COPY THE DATA SET, WITH MODIFCIATIONS
    tempfile copy
    keep a b
    rename a p2
    rename b partner_education
    save `copy'
    
    // MERGE ORIGINAL DATA TO THE COPY
    use dataset, clear
    merge m:1 p2 using `copy', keep(match master)
    Since you did not provide an example of your data, I have not tested this code. The logic of it is correct; it may contain typos or other errors.

    Note that this code assumes that the variable a uniquely identifies observations in the data set.

    Comment

    Working...
    X