Announcement

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

  • How to correctly use headings in coefplot

    Hello,

    I am trying to group some variables on my graph under particular headings using coefplot.

    I want to group variables "SPNEED FSM TRSTADLT YEAR SEX ETHNIC2" under the heading "Confounders"

    I want to group variables "SUGARDRINK ENERDRINK CRSPEAT SWEETEAT FASTFEAT TOTCLEAN DENTFQ VOLUNTFQ PORFRUY PATOTAL LATOTAL ACTTRAV alchabit CARER BULLY2" under the heading "Exposures"

    When I use this code

    Code:
    coefplot (SUGARDRINK ENERDRINK CRSPEAT SWEETEAT FASTFEAT TOTCLEAN DENTFQ VOLUNTFQ PORFRUY PATOTAL LATOTAL ACTTRAV alchabit CARER BULLY2), eform drop(_cons) xline(1) ylabel(, labsize(small)) grid(none) xtitle(Odds ratio) headings(SPNEED FSM TRSTADLT YEAR SEX ETHNIC2= "{bf: Confounders}" SUGARDRINK ENERDRINK CRSPEAT SWEETEAT FASTFEAT TOTCLEAN DENTFQ VOLUNTFQ PORFRUY PATOTAL LATOTAL ACTTRAV alchabit CARER BULLY2= "{bf: Exposures}", gap(0))
    I get the following:

    Click image for larger version

Name:	coefplot headings.png
Views:	1
Size:	108.0 KB
ID:	1762235


    So rather than them being grouped under their respective headings, each variable is assigned the relevant heading. I would really appreciate help with this so headings are appropriately assigned. Thank you.

  • #2
    coefplot is from SSC (FAQ Advice #12).


    headings(SPNEED FSM TRSTADLT YEAR SEX ETHNIC2= "{bf: Confounders}" SUGARDRINK ENERDRINK CRSPEAT SWEETEAT FASTFEAT TOTCLEAN DENTFQ VOLUNTFQ PORFRUY PATOTAL LATOTAL ACTTRAV alchabit CARER BULLY2= "{bf: Exposures}")
    Here, you are supposed to only specify the first variable in the list.

    Code:
    headings(SPNEED = "{bf: Confounders}" SUGARDRINK= "{bf: Exposures}")

    Comment


    • #3
      Thank you for your reply Andrew and apologies I have not specified that coefplot was from SSC.

      I have tried your auggestion before and it produces the following below:

      Click image for larger version

Name:	coefplot headings1.png
Views:	1
Size:	144.4 KB
ID:	1762247


      If it's of any help, the full code that includes how the estimates are produced is as follows:

      Code:
      foreach predictor in SUGARDRINK ENERDRINK CRSPEAT SWEETEAT FASTFEAT TOTCLEAN DENTFQ VOLUNTFQ PORFRUY PATOTAL LATOTAL ACTTRAV alchabit CARER BULLY2 {
              quietly ologit SCWBSG `predictor' SPNEED FSM TRSTADLT YEAR SEX ETHNIC2, or
              estimates store `predictor'
              }
      
                      coefplot (SUGARDRINK ENERDRINK CRSPEAT SWEETEAT FASTFEAT TOTCLEAN DENTFQ VOLUNTFQ PORFRUY PATOTAL LATOTAL ACTTRAV alchabit CARER BULLY2), eform drop(_cons) xline(1) ylabel(, labsize(small)) grid(none) xtitle(Odds ratio) headings(SPNEED = "{bf: Confounders}" SUGARDRINK= "{bf: Exposures}")
      
      graph export SCWBSGmygraph.png
      
      estimates clear
      Thank you.

      Comment


      • #4
        You have to order your coefficients first. See the -order()- option.

        order(coeflist) specifies the order of coefficients (not allowed with at). The default is to use the order as found in the input models
        (and place _cons last, within equations). coeflist is a space-separated list of elements such as:

        . insert a gap
        eq:. insert a gap within equation eq
        coef coefficient coef
        eq: all coefficients from equation eq, in their current order
        eq:coef coefficient coef from equation eq

        where coef may contain "*" (any string) and "?" (any nonzero character) wildcards.

        If no equations are specified, then the requested order of coefficients is repeated within each equation (keeping the existing order
        of equations). Otherwise, the requested order is applied across equations. Note that in the later case the first element in order()
        must be an equation name. eq is applied to all subsequent elements until a new eq is specified. For example, order(5:weight mpg *
        4:turn *) would yield the following order: "weight" from equation "5", "mpg" from equation "5", remaining coefficients from equation
        "5", "turn" from equation "4", remaining coefficients from equation "4", remaining equations if any.

        Comment


        • #5
          That worked Andrew, thank you very much!

          Comment

          Working...
          X