Announcement

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

  • Creating a continuous variable taking date into account

    Dear Statalist,

    I want to do a Cox regression including lung function measurements as a tvc. I have two measurements for each participant, FEV1FVCRMe_NT2BLM and FEV1FVCR_NT3LuM, both continuous variables. These are measured at _t0 (PartDate_NT2BLQ1) and _t (PartDate_NT3BLQ1). I want to create a new variable, FEV1FVC (the tvc variable). How could I create continuous variables from these two, taking into account the dates of measurement?


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(PartDat_NT2BLQ1 PartDat_NT3BLQ1) double(FEV1FVCRMe_NT2BLM FEV1FVCR_NT3LuM)
    13444 17079    .    .
    13114 17293    .  .74
    13619 17675    . .746
    13040     .    .    .
    13537     .    .    .
    13065     .    .    .
    13300 17289    .    .
    13661 17640    .    .
    13522 17538    .    .
    13116 17342    .    .
    13468     .    .    .
    13394     .  .83    .
    13212 17448    .    .
    13117 17385 .724 .745
    13425     .    .    .
    13670 17674    .    .
    13377     .    .    .
    13403     .    .    .
    13654 17689    .    .
    13459 17274    .    .
    13535 17580 .762 .679
    13647     .  .76    .
    13207 17140 .646 .749
        . 17651    .    .
        . 17644    .    .
    13236 17498    .    .
    13124 17282    .    .
    13082 17475 .777    .
        . 17324    .  .56
    13388 17237    .    .
        . 17336    .    .
        . 17553    .    .
    13201     . .654    .
    13216 17489    .    .
    13675 17644    .    .
        . 17189    .    .
    13480 17672    .    .
    13677 17660    .    .
    13472 17667    .    .
    13614     . .741    .
    13065 17343    . .708
        . 17632    .    .
        . 17623    .    .
    13403     .    .    .
    13675 17688    .    .
    13543 17230 .782 .716
    13569     .    .    .
    13683     . .735    .
    13457     .    .    .
    13440     . .568    .
    13293     .    .    .
    13678 17660    .    .
    13055 17321    .    .
    13430 17092   .7   .7
    13165 17395    .    .
    13115     .    .    .
    13135     .    .    .
    13293     . .755    .
        . 17391    .    .
    13079 17447 .874    .
        . 17707    . .899
    13193     .    .    .
    13461 17317    .    .
    13317 17238    .    .
    13123     .    .    .
    13206     .    .    .
    13591 17630 .708   .7
    13475 17566    .    .
        . 17491    .    .
        . 17328    .    .
    13032     .    .    .
    13152     .    .    .
    13289 17589    .    .
    13499 17505    . .748
        . 17406    . .808
    13212     .    .    .
    13130 17205    .    .
    13191     . .636    .
    13310 17283    .    .
    13221 17447    .    .
    13234 17492 .774 .766
    13038 17407    .    .
    13565     .    .    .
        . 17660    .    .
    13255     .    .    .
    13416     .    .    .
        . 17315    .    .
        . 17632    .    .
    13212     .    .    .
    13534     .    .    .
    13375     .    .    .
        . 17290    .    .
    13235 17174    .    .
        . 17475    .    .
    13424 17120    .    .
    13052     .    .    .
        . 17269    . .775
    13628     . .514    .
    13212 17496    . .778
    13289     .    .    .
    end
    format %tdD_m_Y PartDat_NT2BLQ1
    format %tdD_m_Y PartDat_NT3BLQ1
    Best regards,
    Sigrid

  • #2
    I'm not sure if I understand what you want here. Is each observation the data for a single patient? If so, I think you want:

    Code:
    gen long obs_no = _n
    rename FEV1FVCRMe_NT2BLM FEV1FVC2
    rename FEV1FVCR_NT3LuM FEV1FVC3
    
    reshape long PartDat_NT@BLQ1 FEV1FVC, i(obs_no) j(_j)
    You can -drop _j- after that, as you probably will have no further need for it.

    Comment


    • #3
      This is a job for -reshape-. The obstacle is the irregularity of the variable names, so some -rename-ing is required first.

      Code:
      rename *_NT#* *#
      rename FEV1FVCRMe2 FEV1FVC2
      rename FEV1FVCR3 FEV1FVC3
      reshape long PartDat FEV1FVC, i(PID_107945) j(_j)

      Comment


      • #4
        Your -stset- command and your data are not appropriate for each other. You do not say whether you created enddate before or after the reshape, but either way you get the same problem. enddate is based on the value of RegiStat, which is a single value for each person from your original data, presumably the value of RegiStat at the time they exited the study. So, in the end, the value of enddate is the same in both of the new observations per ID that -reshape- created for you. Consequently, with enddate as the time variable in your -stset- command, each person's data is frozen at a single instant in time. With no time progress, there is nothing to analyze!

        I can give you the general outlines of a solution. Get rid of the enddate variable as currently created. Take your -reshaped- data, with the variables PID_107945, PartDate, FEV1FVC, and RegiStat and RegiStatDate. Use -expand- to duplicate the last observation of each person. In the newly created extra observation, and only in that one, use the algorithm you previously used to calculate enddate, and place that value in PartDate. Now set RegiStat to 1 in the original observations. Now run -snapspan-. Now you can -stset- your data correctly with PartDate as the time variable.

        Comment

        Working...
        X