Announcement

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

  • Generating a variable

    I want to generate variable that indicate if individuals continue to participate in a program at age of 72 or after. For example, if an individual participated in the program at age 69 and 73 then a value of 1 should be given, if an individual participated only before the age of 72 then a value of 2 should be given and if an individual participated only at the age of 72 or after then should be given a value of 3.

    A sample of data structure is below.

    e.g.


    ID age Participation_date

    B001 68 05nov2012

    B001 70 07may2015

    B001 72 09jun2017

    B002 67 28nov2011

    B002 68 22oct2012

    B002 69 25nov2013

    B002 70 10nov2014

    B002 71 14dec2015

    B002 72 12dec2016

    B003 73 25feb2012

    B003 75 08oct2013

    B003 77 12feb2016

    B004 76 16jun2012

    B004 78 22may2014

    B005 68 17nov2012

    B006 76 12mar2013

    B006 78 29apr2015

    B007 72 22jun2012

    B007 74 04aug2014

    B008 71 29jan2013

    B008 73 04mar2015

    B008 75 30mar2017

    B009 72 28jan2015

    B010 71 28feb2012

    B010 74 03jun2014

    B011 73 04feb2013

    B011 76 17sep2015

    Thanks for the help

  • #2

    Code:
    bysort ID (age) : gen wabted = cond(age[1] >= 72, 3, cond(age[_N] < 72, 2, 1))

    Comment


    • #3
      Thank you so much Nick.

      Comment

      Working...
      X