Announcement

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

  • coefplot with headers and significance level

    Hello,

    I am trying to plot odds ratios from a logit command - the plots work but I wanted to have
    1) headers for variables, and
    2) asterisk for results that are significant, or show only significant results?


    Here is an example of my data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float covid4 byte(unofflanguage women lico age3 education religion2 canborn) float region
    0 1 1 1 2 3 2 0 4
    1 0 1 1 2 3 2 1 2
    0 1 1 0 2 3 5 0 1
    0 0 0 0 2 3 5 0 1
    1 1 1 0 2 1 1 0 1
    1 1 1 0 2 2 5 0 1
    0 1 1 1 1 3 4 0 .
    1 0 0 0 2 3 5 1 4
    1 1 1 0 2 1 1 0 1
    1 1 1 1 1 1 5 0 2
    1 1 0 0 2 3 1 0 4
    0 1 1 0 2 3 5 0 4
    0 1 0 0 2 3 5 0 1
    1 1 0 0 2 3 5 0 1
    0 1 0 0 1 1 1 0 1
    1 1 0 0 2 3 5 0 .
    1 1 1 0 2 3 2 1 3
    1 1 1 1 2 3 5 0 1
    1 1 1 0 2 3 5 0 1
    0 0 1 0 2 3 3 0 3
    0 1 0 0 2 3 5 0 3
    1 1 1 1 2 3 5 0 1
    1 1 1 0 2 3 5 0 1
    1 1 1 1 2 1 5 0 1
    0 1 0 0 2 3 5 0 1
    . 1 0 0 2 3 5 0 1
    0 1 1 0 2 3 2 0 2
    1 1 1 1 2 3 5 0 1
    0 1 0 0 2 3 2 0 1
    1 1 0 0 2 3 5 0 .
    1 1 1 1 2 3 2 0 2
    0 1 1 1 2 3 5 0 3
    . 1 1 1 . 3 5 0 4
    . 1 1 0 2 3 5 0 1
    1 1 0 0 2 2 5 0 2
    1 1 1 0 2 3 5 0 .
    1 1 1 1 2 3 5 0 .
    1 1 1 1 2 3 5 0 .
    1 1 0 1 1 1 5 0 1
    . 1 1 0 2 3 5 0 1
    0 1 1 0 2 3 5 0 4
    0 0 1 1 2 3 4 0 4
    0 1 0 0 2 3 5 0 4
    1 1 1 0 2 3 2 0 4
    1 1 1 1 3 3 5 0 1
    1 1 0 1 3 3 5 0 1
    0 0 0 1 3 1 2 0 3
    1 1 0 0 2 3 5 1 2
    . 1 1 1 3 3 5 0 3
    0 1 0 0 2 3 2 1 3
    0 1 1 1 2 2 2 0 3
    1 1 0 0 2 3 5 1 2
    0 0 1 0 2 3 3 0 4
    0 1 1 0 2 3 5 1 .
    0 1 1 0 2 3 5 0 .
    0 1 1 1 2 3 1 0 1
    1 1 0 1 2 3 5 0 .
    0 0 0 1 . 3 5 0 1
    . 1 1 1 2 1 5 0 1
    1 1 1 0 1 3 5 0 1
    . 0 1 0 2 3 5 0 1
    0 1 1 1 2 3 5 0 1
    1 1 1 1 2 3 2 0 1
    0 1 0 0 2 3 1 0 1
    . 1 1 0 . 3 2 0 3
    0 1 1 0 2 1 5 0 .
    1 1 1 0 2 3 1 0 2
    1 0 0 0 2 3 5 0 .
    1 1 0 1 2 3 3 0 2
    1 1 1 0 2 3 1 0 1
    1 1 0 0 2 3 2 0 1
    0 1 0 0 2 3 5 0 1
    1 0 0 0 2 3 2 1 .
    1 0 0 1 2 3 5 0 2
    1 1 1 0 2 1 5 0 .
    1 1 1 0 2 3 3 0 2
    1 0 0 0 2 1 2 0 3
    0 0 0 1 1 1 2 1 .
    1 1 1 0 1 3 5 0 4
    0 0 1 0 2 3 5 1 2
    1 0 1 0 1 3 2 0 3
    1 1 1 0 2 3 1 0 1
    1 1 0 1 2 1 2 0 3
    1 1 1 0 2 3 5 0 1
    1 1 0 1 2 3 5 0 1
    1 1 0 0 2 3 5 0 1
    0 1 0 0 2 3 1 0 1
    1 1 0 0 2 3 5 0 2
    1 1 1 1 2 1 1 0 2
    0 1 0 0 2 3 2 0 1
    1 0 1 0 2 3 2 0 3
    0 1 0 0 2 3 1 0 1
    1 1 0 1 3 3 1 0 1
    1 1 0 0 . 3 5 0 2
    . 1 0 0 2 3 5 0 3
    0 0 1 1 2 3 2 1 1
    0 1 0 0 2 3 5 0 3
    1 1 1 0 2 3 5 0 3
    1 0 1 1 2 3 5 0 3
    0 1 0 0 2 3 2 0 3
    end
    label values covid4 experiencelab4
    label def experiencelab4 0 "Never", modify
    label def experiencelab4 1 "Experienced", modify
    label values unofflanguage unofflanguage
    label def unofflanguage 0 "Official language", modify
    label def unofflanguage 1 "Non-official language", modify
    label values women female
    label def female 0 "Non-female", modify
    label def female 1 "Female", modify
    label values lico lico
    label def lico 0 "Non-low-income", modify
    label def lico 1 "Low income", modify
    label values age3 age3
    label def age3 1 "18 to 24", modify
    label def age3 2 "25 to 64", modify
    label def age3 3 "65 to 87", modify
    label values education education
    label def education 1 "High school and below", modify
    label def education 2 "Trade certificate or diploma", modify
    label def education 3 "College, CEGEP, Bachelors and higher", modify
    label values religion2 religion2
    label def religion2 1 "Buddhist", modify
    label def religion2 2 "Christian", modify
    label def religion2 3 "Other (Hindu, Jewish, Taoism, Other religions)", modify
    label def religion2 4 "Muslim, Sikh", modify
    label def religion2 5 "No religious affiliation", modify
    label values canborn canborn
    label def canborn 0 "Outside of Canada", modify
    label def canborn 1 "Inside Canada", modify
    label values region regionlab
    label def regionlab 1 "Central", modify
    label def regionlab 2 "Western", modify
    label def regionlab 3 "Prairies", modify
    label def regionlab 4 "Northern & Atlantic", modify
    Here is my code
    Code:
    quietly logit covid4 ib0.unofflanguage##ib0.women ib0.lico ib1.age3 ib3.education ib5.religion2 ib1.canborn ib1.region
    set scheme meta
    coefplot, drop(_cons) xline(1) eform xtitle(Odds ratio) headings(ib0.unofflanguage##ib0.women = "{bf:Interaction term}" ib0.lico ="{bf:Income status}" ib1.age3 ="{bf:Age group}" ib3.education ="{bf:Education level}" ib5.religion2 ="{bf:Religious identity}" ib1.canborn ="{bf:Country of birth}" ib1.region ="{bf:Region}", labcolor(orange))
    With this code, my categories are just listed without any headers for which categories belong to which variable.

    Thank you!

  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12). Thanks for the data example.

    the plots work but I wanted to have
    1) headers for variables
    Look at how the coefficients are labeled. A double hash sign is no way to reference a coefficient. It is specific factor variable notation to include both the main effects and interactions.

    Code:
    logit covid4 ib0.unofflanguage##ib0.women ib0.lico ib1.age3 ib3.education ib5.religion2 ib1.canborn ib1.region, coeflegend
    Here is some technique, with one of the headers fixed. Below, I define "significant" as P value < 0.10, but you can change this.

    Code:
    coefplot, drop(_cons) xline(1) eform xtitle(Odds ratio) ///
    headings(1.unofflanguage#1.women= "{bf:Interaction term}", labcolor(orange)) ///
    mlab(cond(@pval<0.1, string(@b, "%4.3f")+ "*", "")) mlabpos(1) mlabsize(vsmall)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	26.2 KB
ID:	1704653

    Comment


    • #3
      Thank you so much Andrew Musau ! This really was a big help. I've made a few more tweaks and my graph is so much better.
      For the significance level, is there a way that I could put different conditions such that it will show --> *** p<.01, ** p<.05, * p<.1 ?

      I tried but it returned an "invalid expression in mlabel()"
      Code:
      quietly logit formalsupport ib0.unofflanguage##ib0.women ib0.lico ib1.age3 ib0.covid4  ib0.reexperience4 , or
      coefplot, drop(_cons) xline(1) eform xtitle(Odds ratio) ///
      headings(1.unofflanguage= "{it:Demographic characteristics}" ///
      1.covid4="{it:Experience}" ///
      1.avoidance4="{it:Impact}", labcolor(orange) labsize (vsmall)) ///
      ylabel(, labsize(vsmall)) ///
      mlab(cond(@pval<0.1, string(@b, "%4.3f")+ "*", ""), (@pval<0.05, string(@b, "%4.3f")+ "**", ""), (@pval<0.01, string(@b, "%4.3f")+ "***", "")) mlabpos(1) mlabsize(tiny) msize(small) ///
      title ("First line of title" "second line of title", size(small))
      Last edited by gi peters; 06 Mar 2023, 18:45.

      Comment


      • #4
        See https://journals.sagepub.com/doi/pdf...867X0500500310 on how to include multiple conditions using the -cond()- function.

        Code:
        mlab(cond(@pval<0.01, string(@b, "%4.3f")+ "***",cond(@pval<0.05, string(@b, "%4.3f")+ "**", cond(@pval<0.1, string(@b, "%4.3f")+ "*", "")))) mlabpos(1) mlabsize(vsmall)

        Comment


        • #5
          Thank you so much Andrew Musau! Really appreciate all your help.

          Comment

          Working...
          X