Announcement

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

  • Creating new outcome variable - invalid syntax r(198) problem

    I have twelve disease variables in my dataset. I want to to create an outcome variable "multimorbidity" from those varibales. Here I have drafted the command


    PHP Code:
    local multimorbidity myocardial_inf angina heart_fail heartdisease stroke tb asthma sarcopenia anx hypertension osteoopoross diabetes

    egen multi_morbidity_miss 
    rowmiss(`multimorbidity')

    egen multi_morbidity_total = rowtotal(
    `multimorbidity') if multi_morbidity_miss == 0

    tab1 multi_morbidity_total

    gen multimorbidity_cat = 0 if multi_morbidity_total >= 0 & multi_morbidity_total <=1
    replace multimorbidity_cat = 1 if multi_morbidity_total >= 2 & multi_morbidity_total <=5
    replace multimorbidity_cat = 2 if multi_morbidity_total >= 6 & multi_morbidity_total <=9
    replace multimorbidity_cat = 3 if multi_morbidity_total >= 10 & multi_morbidity_total <=20

    label def multimorbidity_cat 0 "No Multimorbidity" 1 "2 - 5" 3 "6 - 9" 4 ">=10"


    label val multimorbidity_cat multimorbidity_cat

    label var multimorbidity_cat "Categories of multimorbidity" 

    but after running the 3rd command line, my stata is showing

    PHP Code:
    egen multi_morbidity_total rowtotal(`multimorbidity') if multi_morbidity_miss == 0
    invalid syntax
    r(198) 
    What I am missing here? Any help?

    Thanks in advance.
    Last edited by Hasan Bari; 08 May 2021, 11:38.

  • #2
    Probably the following thing is happening:

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . egen rowmiss = rowmiss()
    
    . tab rowmiss
    
        rowmiss |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         74      100.00      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
    . egen rowtotal = rowtotal() if rowmiss==0
    invalid syntax
    r(198);
    and it is happening because you are executing your code line by line, so the local has disappeared by the time you call it.

    Execute the whole block of code together.

    Comment

    Working...
    X