Announcement

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

  • Error while running melogit model

    Hi team,

    I ran a multilevel mixed effect logistic regression model using the following code:

    melogit Depression_Yes_No i.B_E##I_C Residential_status Age Gender Marital_status Education Ethnicity Occupation Income Living_arng Comorbidity DM_family_history Tobacco Alcohol Taking_insulin Taking_OHAs PA DM_duration Recode_hypertension Recode_med_adherence HbA1ctest Foot_care BMI HbA1c, or vce(robust) baselevel

    margins B_E##I_C ///

    marginsplot, allxlabels xscale(range(0 1)) ///

    legend(order(0 "control" 1 "intervention")) xtitle("Time", size(small)) ///

    ytitle("Probability", margin(zero) bmargin(zero) size(small)) ///

    xlabel(0 "Baseline" 1 "Endline", angle(0) labsize(small)) ///

    legend(pos(6) cols(3) size(small)) ylabel(,grid) title("Depression_Yes_No", size(medsmall)) ///

    plot1opts(msymbol(S) lp(shortdash)) ///

    plot2opts(msymbol(T) lp(longdash)) ///

    graphregion(color(white))


    contrast r.B_E@I_C, or



    However, I get an error that says "command legend is unrecognized" and the graph came up with predicted mean instead of predictive probabilities.

    Any help would be highly appreciated.

  • #2
    If your code is laid out exactly as you show it in #1, including the blank lines, that is the cause of your problem. The /// glyph tells Stata that the command continues on the next physical line in the code. As written, that line has nothing on it. So Stata thinks that the -marginsplot- command ends after the -xscale()- option. There is nothing that tells Stata that it continues on the line that starts with -legend()-. So Stata thinks you want it to execute some command named -legend-, but there is no such command, hence the message.

    Just remove the blank lines from your code and you should be fine. (Or, if you really want the blank lines for aesthetic reasons, put /// at the end of each of them within the -marginsplot- command. The extra ///'s will tell Stata to keep looking for more of the command on the following line.

    Comment


    • #3
      Thank you so much Clyde. Removing blank lines from the code worked.

      Comment

      Working...
      X