Announcement

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

  • Graph twoway scatter with 95% CI and Odds Ratio

    I got a dataset with 2 group of ppl (group1 is male, group 2 is female), and I got their odds ratio, and 95% CI. Represented as “ll, ul” in my dataset.
    Now I tried to graph a two-way scatter graph, with their risk_score as x-axis and OR as y-axis, with 95%Ci. And I only need 2 legends in my graph, which are two dots of OR, but do not need legend of 95% CI (ll/ul)
    i tried two ways, by constructing two datasets,
    For dataset 1, I pooled all ppl and divided into 2 groups, and here is my code:
    Code:
    twoway ///
    (rcap ll ul risk_score, vertical) ///
    (scatter or risk_score  if group == 1, mcolor(red)) ///
    (scatter or risk_score  if group == 2, mcolor(blue)) ///
    xtitle ("Risk score") ytitle("ORs") legend(label1(2 "OR with male HH") label(3"OR with female HH”)
    The results did not return a graph, plus, it said "parentheses do not balance”.
    So I tried another way by using dataset2. My code is:
    Code:
    twoway scatter or risk_score
    twoway (scatter male_ors risk_score, yaxis(1)) || rcap male_ll male_ul risk_score /// 
           (scatter female_ors risk_score, yaxis(2)) || rcap female_ll female_ul risk_score ///
       xtitle ("Risk score") ytitle("ORs") legend(label1(2 "OR with male HH") label(3"OR with female HH")
    And Stata showed similar results as above.
    May I know how to deal with this? Thank you so much!

  • #2
    legend(label1(2 "OR with male HH") label(3"OR with female HH)
    Small details matter here. You do not have a closing parenthesis, the first label option is misspelled and the highlighted closing double quote is not the correct character. As you do not present a reproducible example, I cannot guarantee that these are the only issues. Bottom line, you need to look at your code closely.

    Code:
    legend(label(2 "OR with male HH") label(3 "OR with female HH"))

    Comment

    Working...
    X