Announcement

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

  • First observation from panel data

    I have the following panel data of one individual in the study. WHO stage was recorded multiple times, but I only want to identify the first record of WHO stage, make a new variable for this first WHO stage and copy that stage to all observations of the panel data for the individual. The data looks as follows:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double id byte who_stage float visit_lab_date
    829 .     .
    829 4 20898
    829 .     .
    829 .     .
    829 .     .
    829 . 20919
    829 .     .
    829 .     .
    829 .     .
    829 .     .
    829 3 20954
    829 .     .
    829 .     .
    829 . 21014
    829 .     .
    829 .     .
    829 . 21133
    829 .     .
    829 .     .
    829 .     .
    829 1 21336
    829 .     .
    829 1 21336
    829 .     .
    829 . 21417
    829 . 21417
    829 . 21417
    829 . 21417
    829 . 21417
    829 1 21427
    829 .     .
    829 .     .
    829 . 21427
    829 .     .
    829 .     .
    829 .     .
    829 . 21623
    829 .     .
    829 1 21623
    829 . 21735
    829 .     .
    829 1 21735
    829 .     .
    829 .     .
    829 1 21882
    829 .     .
    829 1 21882
    829 .     .
    829 . 21910
    829 .     .
    829 .     .
    829 . 21939
    829 .     .
    829 . 21970
    829 . 21999
    829 . 21999
    829 . 21999
    829 . 21999
    829 . 21999
    829 1 22092
    end
    format %td visit_lab_date
    Thanks in advance for all your time and help!

  • #2
    Salome_Joelle:
    do you mean:
    Code:
    . bysort id ( visit_lab_date ): gen wanted= who_stage[1]
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      I used exactly that, but for some cases (e.g. id 42) it didn't pick up on this as shown below:

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input long rowo byte who_stage float(visit_lab_date who_stage_first)
      42 . 21369 .
      42 . 21369 .
      42 . 21381 .
      42 . 21381 .
      42 . 21381 .
      42 . 21381 .
      42 . 21381 .
      42 . 21381 .
      42 . 21381 .
      42 . 21573 .
      42 . 21573 .
      42 1 21573 .
      42 . 21573 .
      42 . 21573 .
      42 1 21753 .
      42 . 21753 .
      42 1 21934 .
      end
      format %td visit_lab_date
      There was 3 instances of a WHO stage being recorded but all the observations of the new variable are missing

      Comment


      • #4
        Maybe you want:

        Code:
        bys rowo (visit_lab_date): gen firstob= sum(sum(!missing(who_stage)))==1
        bys rowo: egen wanted= max(cond(firstob, who_stage, .))

        Comment

        Working...
        X