Announcement

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

  • Imposing a gap between bars for marginsplot

    I am conducting a latent class analysis of a set of 9 questions about vaccine hesitancy. I’m creating bar graphs to describe each of four resultant classes from my model, to describe the pattern of responses to these 9 questions within each class. Responses range from 1 to 3 (corresponding to “Agree”, “Neither Agree nor Disagree”, and “Disagree”). I need four identical bar graphs, with x axis representing each of the 9 questions, and y axis representing responses and set to display values between 1 and 3 (inclusive). I'm having difficulty using options to separate the bars so they are visually distinct. I have tried "bargap" and "gap" and "barwidth" and "ascategory" options, but keep getting the "option X not allowed" error message

    How do I separate the bars, so a small amount of empty space appears between each bar? marginsplot doesn't appear to be working like the traditional graph bar command (or, perhaps more likely, I'm putting my options in the wrong place?).

    Here’s my code, an example from one of the four classes from my LCA:

    margins, predict(outcome(vhs_lf_important_recode2) class(4)) predict(outcome(vhs_lf_community_recode2) class(4)) predict(outcome(vhs_lf_beneficial_recode2) class(4)) predict(outcome(vhs_lf_reliableinfo_recode2) class(4)) predict(outcome(vhs_lf_protect_recode2) class(4)) predict(outcome(vhs_lf_doctor_reccomend_recode2) class(4)) predict(outcome(vhs_lf_notcommon2) class(4)) predict(outcome(vhs_lf_adverseevents2) class(4)) predict(outcome(vhs_lf_morerisks2) class(4))

    marginsplot, recast(bar) xtitle("") ytitle("") xlabel(1 "Important" 2 "Community" 3 "Beneficial" 4 "Reliable Info" 5 "Protect" 6 "Dr Recommend" 7 "Not Common" 8 "AEs" 9 "More Risks", angle(45)) title("Lassa Fever VHS Responses For Vaccine Skeptics Class with 95% CI") ylabel(1 2 3) saving(vaccine_skeptics_lca, replace)



    I've attached the resultant graph

    Thanks for any help you can offer.
    Attached Files

  • #2
    Code is no good here. Present a reproducible example (not necessarily with your real data). See FAQ Advice #12 for details.

    Comment


    • #3
      Hmm. I see the forums prefer graphs and figures in .png, but Stata doesn't produce those?

      I'm also unable to post the data unfortunately, and uncertain how to create "fake" data that would work in this example... My apologies, I will try to sort this out myself.

      Comment


      • #4
        Originally posted by Matt Price View Post
        Hmm. I see the forums prefer graphs and figures in .png, but Stata doesn't produce those?
        After producing the graph, use 'graph export' with *.png extension to save the graph in *.png fomat

        Code:
        graph export graph_name.png, replace
        Roman

        Comment

        Working...
        X