Announcement

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

  • Get the status of a variable at month of admissions (with monthly status information in wide form)

    Hi,

    I have data of the following form:


    clear
    input id month s_01 s_02 s_03 s_04 s_05 s_06 s_07 s_08 s_09 s_10 s_11 s_12
    101 5 0 0 0 0 1 1 1 1 1 1 1 1
    102 2 1 0 0 0 0 1 1 1 1 1 1 1
    end

    Month is the month the patient was admitted to the institution, s_01 stands for the status of the patient in a January, s_02 is their status in February and so on, the variable stands for whether they were insured in that month. I want to construct a new variable that equals to whether or not the patient was insured in the month they were admitted. i.e. for patient 101 the value should be 1 and for patient 102 the value should be 0. Is there a way to do this without having to reshape the data to long form first?

    Thanks.

    Best,
    Angela






  • #2
    Yes, it can be done.
    Code:
    gen wanted = .
    forvalues i = 1/12 {
        local ii: display %02.0f `i'
        replace wanted = s_`ii' if month == `i'
    }
    But what is your objection to -reshape-ing the data to long? Probably whatever else you are going to do with this data will also be easier in long layout than in wide. Unless you know of some specific reason why your overall analysis will be facilitated by using wide layout, you should switch to long because most things in Stata are easier that way.

    Comment


    • #3
      Hi Clyde,

      Thanks for your help. I don't want to reshape because the status variable is merged from another wide dataset and it is the only information I need from that dataset.

      Best,
      Angela

      Comment

      Working...
      X