Announcement

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

  • Generate variable from other individual's id

    Dear Stata users,
    I am using the German Socio-economic panel data. I am using the following variables: persnr (which is the id of the individual), fatherpersnr (which is the father id of the individual, in this panel data some of the people surveyed in the household are parents and children) and birthcountry.
    I would like to generate a new variable: fatherbirthcountry. I have been thinking on a strategy to solve this but nothing came to my mind. Could anyone please give me some help?
    Thank you!

  • #2
    Marta:
    wouldn't -egen- with the -group- function be an option?
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you, Carlo Lazzaro for your answer; but I am still not seeing how it can work.
      I will give an example to make my situation clearer:
      persnr fatherpersnr birthcountry
      1
      2
      3
      .
      1
      .
      US
      UK
      Germany
      and I want to obtain
      persnr fatherpersnr birthcountry fatherbirthcountry
      1
      2
      3
      .
      1
      .
      US
      UK
      Germany
      .
      US
      .

      Comment


      • #4
        In the future, please post data using the -dataex- command (see FAQ 12.2--https://www.statalist.org/forums/help#stata)

        Here's an example:
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float(persnr fatherpersnr) str7 birthcountry
        1 . "US"     
        2 1 "UK"     
        3 . "Germany"
        4 . "Mexico"
        5 . "Brazil"
        6 4 "France"
        end
        I think, the following code will give you what you want:

        Code:
        preserve
        keep persnr birthcountry
        rename persnr fatherpersnr
        rename birthcountry fatherbirthcountry
        save father_info.dta, replace
        restore
        merge m:1 fatherpersnr using father_info.dta
        drop if _merge==2
        sort persnr
        Stata/MP 14.1 (64-bit x86-64)
        Revision 19 May 2016
        Win 8.1

        Comment

        Working...
        X