Announcement

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

  • Replacing variable values by the value of other variables

    Hi all,

    I have a panel dataset where i'm trying to create a variable that lists the month and year in which a given event first occured, however i'm struggling with the format of the date variables. I have variables for each individual wave of data collection that specify the month (iintdatmw*) and year (iintdatyw*) data was collected.

    idauniq iintdatmw1 iintdatyw1 iintdatmw2 iintdatyw2
    100035 10 2002 2 2005
    100035 10 2002 2 2005
    100035 10 2002 2 2005
    100035 10 2002 2 2005
    100035 10 2002 2 2005
    100035 10 2002 2 2005
    100035 10 2002 2 2005
    100035 10 2002 2 2005
    100035 10 2002 2 2005

    I have the data in long format so there are 9 observations for each wave of study, shown for id 100035 above. The data shows that in w1 this person was interviewed 10/2002 and in w2 interviewed 2/2005 – is there a way to create variables that would give the month and year also in long form? I have ~12000 obs in this dataset and have been wracking my brain over finding a solution, any help would be appreciated!

    Many thanks,
    Robyn

  • #2
    Does this help?

    Code:
    gen ymw1 = ym(intdatyw1, intdatmw1) 
    format ymw1 %tm

    Comment


    • #3
      Hi Nick,

      Thanks for the reply. This code has helped – i've done the following for each wave:

      gen ymw1 = mdy(intdatmw1, day, intdatyw1)
      format ymw1 %d

      My data now looks like this:

      idauniq ymw1 ymw2 ymw3 ymw4
      100039 15may2002 15sep2004 15aug2006 15aug2008
      100039 15may2002 15sep2004 15aug2006 15aug2008
      100039 15may2002 15sep2004 15aug2006 15aug2008
      100039 15may2002 15sep2004 15aug2006 15aug2008

      whereas I need a variable that looks like this:

      100039 15may2002
      100039 15sep2004
      100039 15aug2006
      100039 15aug2008

      Appreciate the help, thanks!

      Comment


      • #4
        Code:
        h reshape
        my guess as to the needed code (assumes these are the only variables):
        Code:
        reshape long ymw, i(idauniq) j(count)
        you can replace "count" with whatever variable name you want

        Comment

        Working...
        X