Announcement

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

  • Generating a new variable that includes the content of another variable from one panel to all panels

    Hello All,

    My data are in long format, and I have multiple (up to 16) measurements per participant and they can be at different organizations (there are 25 organizations) at each measurement. I am trying to create a variable that populates the ID of the first organization (first_org) they were at when they first joined the study. For example, in the data example below I would like ID 11000 to have 1 populated for every cycle under a new variable first_org.

    I came across the following Stata FAQ, however, I am failing at conceiving how I can adapt any of the code provided in there to my situation. Does anyone have a suggestion or recommendation?

    Thank you for your time and assistance.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(ID cycle organization)
    11000  1  1
    11000  2  1
    11000  3  1
    11000  4 20
    11000  5 20
    11000  7 20
    11000  8 20
    11000  9 20
    11000 10 20
    11000 11 20
    11000 12 20
    11001  1  1
    11001  2  1
    11001  3  1
    11001  4 20
    11001  5 20
    11001  7 20
    11002  1  1
    11002  2  1
    11002  3  1
    11002  5 20
    11002 10 20
    11002 13 23
    11002 14 23
    11002 15 23
    11003  1  1
    11003  3  1
    11003  4 20
    11003  5 20
    11003  7 20
    11004  1  1
    11004  2  1
    11004  3  1
    11004  4 20
    11004  5 20
    11004  7 20
    11004  8 20
    11004  9 20
    11004 10 20
    11004 11 20
    11004 12 20
    11004 13 23
    11004 14 23
    11004 15 23
    11005  2  1
    11005  3  1
    11005  5 20
    11005  7 20
    11005  8 20
    11005  9 20
    11005 10 20
    11005 11 20
    11005 12 20
    11005 13 23
    11005 14 23
    11005 15 23
    11005 16 23
    11006  1  1
    11006  2  1
    11006  3  1
    11006  5 20
    11006  7 20
    11006  8 20
    11006  9 20
    11006 10 20
    11006 11 20
    11006 12 20
    11006 13 23
    11006 14 23
    11006 15 23
    11006 16 23
    11007  1  1
    11007  2  1
    11007  3  1
    11007  4 20
    11007  5 20
    11007  8 20
    11007  9 20
    11007 10 20
    11007 11 20
    11007 12 20
    11007 13 23
    11007 14 23
    11007 15 23
    11007 16 23
    11008  1  1
    11008  2  1
    11008  3  1
    11008  4 20
    11008  5 20
    11008  7 20
    11008  8 20
    11008  9 20
    11008 10 20
    11008 11 20
    11008 12 20
    11008 13 23
    11008 14 23
    11008 15 23
    11009  1  1
    end

  • #2
    If I understand exactly what you need, this code should have.

    What make me could not be sure is the noticing that ID 11005 has no cycle 1, but starting with cycle 2.
    Code:
    bys ID (cycle): gen first_org = organization[1]

    Comment


    • #3
      Hello Romalpa,

      Yes not all participants joined at cycle 1. As you noticed they could have joined at any cycle from cycle 1 to 13.

      I believe that the code that you provided was exactly what I was looking for. I am just double checking the sample that I get.

      Best wishes and thank you,
      Patrick

      Comment

      Working...
      X