Announcement

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

  • Code to generate new variables for determining prevalence of organism carriage among hospital staff




    Dear Statalist
    I have been trying to generate a new variable that will help me determine the prevalence of staphylococcus carriage (S. aureus or CoNS) among participants. That is supposed to be the number of people among the 51 participants who had either S.aureus or CoNS, irrespective of whether it was right nostril, left nostril, right finger nail bed, or left finger nail bed (rn, ln, rfn, lfn). So any participant that had at any site should be ‘yes’ otherwise ‘no’ , unless the data is missing.
    I have tried several codes shown below

    generate staph_total =.

    replace staph_total ="yes" if organism_rn == "S. aureus"|" CoNS" & organism_ln == "S. aureus"|" CoNS" & organism_rfn == "S. aureus"|" CoNS" & organism_lfn == "S. aureus"|" CoNS"

    replace staph_total =1 if organism_rn == "S. aureus"|" CoNS" & organism_ln == "S. aureus"|" CoNS" & organism_rfn == "S. aureus"|" CoNS" & organism_lfn == "S. aureus"|" CoNS"

    replace staph_total =1 if organism_rn == 1|2 & organism_ln == 1|3 & organism_rfn == 2|4 & organism_lfn == 2|5

    replace staph_total =0 if organism_rn == 4 & organism_ln == 2|4 & organism_rfn == 1|3 & organism_lfn == 3|4

    All failed.

    The dataset is also shown below

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(organism_rn organism_ln organism_rfn organism_lfn)
    2 3 4 5
    1 1 . .
    1 1 . .
    1 1 4 3
    2 3 . .
    1 1 . .
    . . 3 .
    2 3 4 5
    . . . .
    . . . .
    1 1 . .
    . 1 4 .
    . 3 4 .
    . . . .
    . 1 . .
    1 . . 4
    . . . .
    2 . 2 2
    . 3 2 .
    2 3 . .
    2 3 4 5
    . 1 2 .
    . 1 . 2
    . . . .
    2 3 4 .
    . . . .
    . . . 4
    . . . .
    . 3 2 2
    . . 4 .
    . . 3 .
    1 1 . .
    . . 2 2
    . 3 4 .
    . . . .
    . . . .
    . . . .
    4 4 . .
    . . . 5
    . . . .
    . . . .
    . . 1 .
    . . 4 .
    . 2 . .
    . . . .
    . . . .
    . . 3 3
    2 3 . .
    1 . . .
    . 1 . .
    1 . . .
    end
    label values organism_rn rn_organism1
    label def rn_organism1 1 "CoNS", modify
    label def rn_organism1 2 "S. aureus", modify
    label def rn_organism1 4 "Streptococcus spp", modify
    label values organism_ln ln_organism1
    label def ln_organism1 1 "CoNS", modify
    label def ln_organism1 2 "E. coli", modify
    label def ln_organism1 3 "S. aureus", modify
    label def ln_organism1 4 "Streptococcus spp", modify
    label values organism_rfn rfn_organism1
    label def rfn_organism1 1 "Bacillus spp", modify
    label def rfn_organism1 2 "CoNS", modify
    label def rfn_organism1 3 "E. faecalis", modify
    label def rfn_organism1 4 "S. aureus", modify
    label values organism_lfn lfn_organism1
    label def lfn_organism1 2 "CoNS", modify
    label def lfn_organism1 3 "E. coli", modify
    label def lfn_organism1 4 "E. faecalis", modify
    label def lfn_organism1 5 "S. aureus", modify

    I would appreciate any suggestions.
    Thank you
    Obum Ezeanosike

  • #2
    there are several problems with your code; instead of fixing it, instead try this:
    Code:
    gen byte staph_total=inlist(organism_rn,1,2) | inlist(organism_ln,1,3) | inlist(organism_rfn,2,4) | inlist(organism_lfn,2,5)
    I suggest also that you read the User's Guide manual as it covers most of the errors (such as how to use the "or" symbol (|)

    Comment


    • #3
      Thank you Rich
      It worked well.
      I will also find relevant sections of the manual and read again

      Obum

      Comment

      Working...
      X