Announcement

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

  • Macro regression with survey context

    Hello,

    I want to run a regression and subsequent prediction separately for 23 independent variables . I hereby use a negative binomial regression in a survey context.
    Without a macro the syntax would be:

    svy:nbreg av_tot_cost1 b2.bmi_class b1.age3c i.hc04 ib(freq).et_1 I.ma0101, baselevels irr

    predict p_ma0101

    svy:nbreg av_tot_cost1 b2.bmi_class b1.age3c i.hc04 ib(freq).et_1 I.ma0102, baselevels irr

    predict p_ma0102

    .... up to ma0123


    I have run the following macro but get the comment 'invalid syntax'


    foreach disease of ma0101 ma0102 ma0103 ma0104 ma0105 ma0106 ma0107 ma0108 ma0109 ma0110 ma0111 ma0112 ma0113 ma0114 ma0115 ma0116 ma0117 ma0118 ma0119 ma0120 ma0121 ma0122 ma0123 {
    svy:nbreg av_tot_cost1 b2.bmi_class b1.age3c i.hc04 ib(freq).et_1 i.`disease', baselevels irr
    predict p_$disease}


    Can someone help me to correctly adapt the code?

    Thank you in advance


  • #2
    Welcome to Statalist.

    The index of your foreach loop is the local macro "disease". To use its value, you should reference it as
    Code:
    `disease'
    as you did in your nbreg command. However, you referenced "disease" as if it were a global macro in your predict command. You instead need
    Code:
    predict p_`disease'
    For more background on local and global macros, look at Section 18.3 in the Stata User's Guide PDF manual included in your Stata installation and accessible from Stata's Help menu.
    Last edited by William Lisowski; 13 May 2019, 09:24.

    Comment

    Working...
    X