Announcement

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

  • pid - Creating a variable that assigns values from a partner/relation

    Dear Forum Users,

    I would like to create a variable that records the social class of an individual's partner.

    Each individual in my dataset has a unique personal identifier 'pid'. Furthermore, if an individual has a partner in the dataset, their partner can be identified by variable 'sppid', which takes the pid value that corresponds to the individual's partner.

    I have created a categorical variable, 'dgold', which records the social class of each individual. However, I would now like to create a categorical variable 'sgold', which takes the dgold value that corresponds to the individual's partner.

    I would be very grateful if someone was able to recommend how I might achieve this.

    Kind regards,

    Harrison

  • #2
    Try this:

    Code:
    preserve
    keep pid dgold
    rename pid sppid
    rename dgold sgold
    tempfile holding
    save `holding'
    restore
    merge 1:1 sppid using `holding'
    Note: This assumes that each value of sppid occurs only once in the data set. If the same person is listed as the spouse of more than one person (polygamy or just different time periods) then this code will not work (it will break at the -merge- command). But in that case you also have another problem: if a person can appear as a spouse more than once, their values of dgold may differ and you need to decide how you will reconcile those inconsistencies.

    This also assumes that each value of pid occurs only once. If there are multiple records per pid, you have similar problems to what I described above.

    Comment


    • #3
      Thanks, again, Clyde!

      Comment


      • #4
        In addition to Clyde's helpful hints, see http://www.stata-journal.com/sjpdf.h...iclenum=dm0043

        Comment


        • #5
          Thanks, Nick!

          Comment

          Working...
          X