Announcement

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

  • Inserting numeric value across same IDs

    Hi all,

    My data is longitudinal data and participants were asked if they experienced yellow eyes(eyesyell) or/ and vomiting(aesnausea). However this was only asked at a particular clinic visit of many (visname).

    extra stands for how many similar participant ids are present in the dataset.

    So I created a variable livsymp which I coded as 0 for those that experienced aesnausea and 1 for eyesyell.

    My question is how can I code 0 and 1 respectively across all participant Ids as I intend on dropping if extra >=1 as I intend to merge the dataset to another.

    Please see data output below. I am using Stata 15.1





    dataex participantid visname eyesyell aesnausea livsymp extra if extra >=0 & eyesyell==1| aesnausea==1

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str12 participantid str31 visname byte(eyesyell aesnausea) float livsymp byte extra
    "297-01020-1" "1 Month"               0 1 0 2
    "297-04020-4" "1 Month"               0 1 0 3
    "299-00299-0" "Unscheduled Visit"     0 1 0 3
    "33-00052-3"  "1 Month"               0 1 0 5
    "33-00294-1"  "1 Month"               0 1 0 3
    "33-00317-7"  "1 Month"               0 1 0 5
    "33-00762-1"  "1 Month"               0 1 0 5
    "33-00917-3"  "1 Month"               0 1 0 5
    "33-00954-4"  "Unscheduled Visit"     0 1 0 1
    "33-01099-5"  "14M p3HP Clinic Visit" 0 1 0 5
    "33-01155-8"  "Unscheduled Visit"     0 1 0 3
    "33-01198-5"  "Unscheduled Visit"     0 1 0 6
    "500-00023-0" "Unscheduled Visit"     0 1 0 3
    "500-00056-6" "1 Month"               1 0 1 3
    "500-00062-3" "14M p3HP Clinic Visit" 0 1 0 4
    "500-00177-0" "Unscheduled Visit"     0 1 0 0
    "500-00265-8" "1 Month"               0 1 0 9
    "502-00016-4" "1 Month"               0 1 0 5
    "502-00450-6" "15M p3HP Clinic Visit" 0 1 0 5
    "502-00687-8" "Unscheduled Visit"     0 1 0 6
    "502-00689-0" "2 Months"              0 1 0 2
    "502-00861-2" "1 Month"               0 1 0 2
    "506-00328-4" "13M p3HP Clinic Visit" 0 1 0 5
    "888-00033-0" "1 Month"               0 1 0 2
    "888-00035-2" "1 Month"               0 1 0 4
    "888-00080-2" "2 Months"              1 0 1 5
    "888-00260-2" "3 Months"              0 1 0 2
    "888-00287-1" "14M p3HP Clinic Visit" 0 1 0 5
    "888-00333-3" "2 Months"              0 1 0 5
    end
    label values aesnausea cYN
    label values eyesyell cYN
    label def cYN 0 "No", modify
    label def cYN 1 "Yes", modify
    label values livsymp livsymp_
    label def livsymp_ 0 "Nausea", modify
    label def livsymp_ 1 "Yellow eyes", modify
    ------------------ copy up to and including the previous line ------------------

  • #2
    Originally posted by Galenda Nagudi View Post

    So I created a variable livsymp which I coded as 0 for those that experienced aesnausea and 1 for eyesyell.
    Are these conditions mutually exclusive across participants? If not, then the variable cannot be generated as you wish.

    My question is how can I code 0 and 1 respectively across all participant Ids as I intend on dropping if extra >=1 as I intend to merge the dataset to another.
    Assuming that the conditions are mutually exclusive:

    Code:
    assert inlist(eyesyell, 0, 1) & inlist(aesnausea, 0, 1)
    gen wanted= cond(eyesyell & !aesnausea, 1, cond(!eyesyell & aesnausea, 0, .))
    gsort participantid -wanted
    by participantid: replace wanted= wanted[1] 
    label values wanted livsymp_
    label def livsymp_ 0 "Nausea", modify
    label def livsymp_ 1 "Yellow eyes", modify

    Comment


    • #3
      Thank you Andrew for the response.

      Thank you for pointing out the aspect of mutual exclusivity of events. As per the study, there was a possibility of participants reporting both symptoms however, none of the participants did. Therefore, I have treated them as mutually exclusive events and gone ahead to use the code and it has worked. Thanks again.

      Comment

      Working...
      X