Announcement

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

  • I want to duplicate values of a variable for the same identifier

    Hello,

    I am working with a dataset that has households' IDs matched with individuals' IDs, so that each household has multiple individuals. In this dataset I have a variable related to the education of the mother that has a value for only one individual in the household while the rest of the individuals in the household has missing values for this variable. Accordingly I need a command that duplicates the existing value for all individuals in the same household. Kindly find below an example of the data and what I need to excute:

    hhid indid mothedu
    1 11 .
    1 12 .
    1 13 Secondary

    2 21 .
    2 22 Primary

    3 31 .
    3 32 .
    3 33 University

    What I need to do:

    hhid indid mothedu
    1 11 Secondary
    1 12 Secondary.
    1 13 Secondary

    2 21 Primary
    2 22 Primary

    3 31 University
    3 32 University
    3 33 University


    I hope I was clear enough in explaining the issue and thank you in advance.

    Noha

  • #2
    The solution depends on whether "motheredu" is a string variable or a numeric variable with value labels. For strings


    Code:
    bys hhid (mothedu): replace mothedu=mothedu[_N]
    For a numeric variable with value labels

    Code:
    bys hhid (mothedu): replace mothedu=mothedu[1]

    Comment


    • #3
      Thanks a lot, will try this

      Comment

      Working...
      X