Announcement

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

  • Construct two variables for unemployment at age 16 or 22

    Dear Stata Team,

    I would like to construct two variables for unemployment (nun) when an individual is 16 years of age (nun_highschool) conditional on hiqual==4 and when an individual is 22 years of age (nun_uni) conditional on hiqual==1.
    I would need the respective variables for a given individual over the survey years time invariant.
    I hope this explanation makes sense.
    I would appreciate your help.

    Best,
    Nico



    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long id float(year nun age) byte hiqual
      6135 1992 11.8 20 4
      6135 1993 12.4 21 4
     12935 1993    8 20 4
     12935 1995  6.9 22 4
     17015 1997    6 16 4
     17015 1998  5.5 17 4
     17015 2003  4.4 22 1
     22445 2000  4.9 16 4
     29259 1995  6.9 21 4
     29259 1996  6.4 22 4
     29925 1993    8 16 4
     29925 1994  7.4 17 4
     29925 1999  5.3 22 1
     30615 1994 11.3 17 4
     47619 2004  5.2 16 4
     47619 2005  5.3 17 4
     48303 2006  5.8 16 4
     50335 1992  7.7 16 4
     50335 1993    8 17 4
     61215 2005  4.4 16 4
     75495 1996  6.4 17 4
     76165 1999  5.3 17 4
     81682 1997    6 21 4
     81682 1998  5.5 22 4
     96575 1995  6.9 22 1
    134655 2001  5.7 16 4
    138055 1997  7.9 17 4
    163215 1996  6.4 16 4
    163215 1997    6 17 4
    163899 2001  5.7 16 4
    170699 1998  5.5 20 4
    170699 1999  5.3 21 4
    173411 1997    6 16 4
    173411 1998  5.5 17 4
    182255 1997    6 16 4
    182255 1998  5.5 17 4
    182255 2001  4.5 20 4
    182255 2002  4.6 21 4
    182939 2004  5.2 17 4
    184965 1998    7 16 4
    184965 1999  6.7 17 4
    184965 2002  5.8 20 4
    184965 2003  5.6 21 4
    184965 2004  5.2 22 4
    201295 1992  7.7 20 4
    201295 1994  7.4 22 4
    211491 2002  4.6 16 4
    211491 2007    . 21 4
    211491 2008    . 22 4
    218291 1992  7.7 17 4
    242775 1999  5.3 17 4
    252971 1993    8 16 4
    252971 1994  7.4 17 4
    261125 2001  5.7 16 4
    261125 2007  5.7 22 1
    280165 1995  6.9 16 4
    280165 1996  6.4 17 4
    280165 1999  5.3 20 4
    280165 2000  4.9 21 4
    280859 2002  5.8 17 4
    284939 1994 11.3 20 4
    284939 1995 10.1 21 4
    294459 1993 12.4 22 1
    303299 1992 11.8 20 4
    303299 1994 11.3 22 4
    307375 1994 11.3 22 1
    308731 1995 10.1 16 4
    308731 1996  9.6 17 4
    314175 1994  7.4 20 4
    326423 1995  6.9 17 4
    330495 1992  7.7 17 4
    331179 1993    8 16 4
    333205 2006  5.1 16 4
    346882 2000  4.9 21 4
    353615 1998    7 17 4
    355655 1998  5.5 20 4
    355655 1999  5.3 21 4
    362459 1992  7.7 21 4
    362459 1993    8 22 4
    387605 2004  4.4 16 4
    389651 2004  4.4 17 4
    392379 1996  9.6 16 4
    397135 1992 11.8 16 4
    397135 1993 12.4 17 4
    397135 1996  9.6 20 4
    397135 1997  7.9 21 4
    397135 1998    7 22 4
    399859 1994  7.4 20 4
    399859 1995  6.9 21 4
    399859 1996  6.4 22 4
    402575 1993 12.4 20 4
    402575 1994 11.3 21 4
    402575 1995 10.1 22 4
    410735 1998    7 16 4
    410735 1999  6.7 17 4
    410735 2002  5.8 20 4
    410735 2003  5.6 21 4
    410735 2004  5.2 22 4
    448135 1992 11.8 21 4
    448135 1993 12.4 22 4
    end
    label values hiqual hiqual
    label def hiqual 1 "Degree", modify
    label def hiqual 4 "GCSE etc", modify

  • #2
    I'm not sure I understand what you want here. You refer to a variable nun_uni which does not appear in your example data. In addition, you have a variable called nun which you describe as unemployment, but it is not a categorical variable--it is clearly a continuous numeric variable, so I'm not sure what it really means.

    Anyway, taking your words at face value:
    Code:
    isid id age, sort
    by id (age): egen unemp_16 = max(cond(age == 16 & hiqual == 4, nun, .))
    by id (age): egen unemp_22 = max(cond(age == 22 & hiqual == 1, nun, .))
    will create two numeric variable. For unemp_16, Stata will find, for each id, the observation in which age == 16 and hiqual == 4, and unemp_16 will be set to the value of nun in that observation across all observations for that id. If, as is the case for many of your id's, there is no observation with age == 16 and hiqual == 4, unemp_16 will have a missing value. The workings of unemp_22 are analogous.

    If that is not what you wanted, when posting back, I suggest a more thorough explanation of what is desired, and also show the results from a hand-worked example on a few id's.

    Comment


    • #3
      Hi Clyde,
      The way you interpreted my question was correct, this is exactly what I wanted.
      I re-read my question and I conclude that it was not all that clear.
      My apologies about that. I will try your code later in the day.
      Thanks again for your help.
      Best,
      Nico

      Comment


      • #4
        See also


        SJ-11-2 dm0055 . . . . . . . . . . . . . . Speaking Stata: Compared with ...
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
        Q2/11 SJ 11(2):305--314 (no commands)
        reviews techniques for relating values to values in other
        observations


        https://journals.sagepub.com/doi/pdf...867X1101100210

        where the method used by Clyde Schechter will be found documented in Section 9.

        Comment


        • #5
          Thanks, Nick, I will have a look at that.
          Have a great day both, and thanks for replying.
          Best,
          Nico

          Comment

          Working...
          X