Announcement

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

  • The same code for coefplot yields different results

    Dear Stata users,

    I'm new here and I have a problem which I'm, unfortunately, unable to solve. I'm plotting odds ratios from logistic regression using coefplot (Stata 16.1). Below is my code for the plot:

    Code:
    xi: asdoc logit child1 ln_time i.edu_level i.married i.pgemplst i.cohort  num_s, cluster(pid) nolog or
        
    coefplot, title({bf:Transition to first birth}) subtitle(Odds Ratio) eform drop(ln_time _cons) xlabel(0(1)5) xscale(range(0(1)5)) headings(2.edu_level="{it:Education Level}" 2.married="{it:Marrital Status}" 2.pgemplst="{it:Employment Status}" 2.cohort="{it:Cohort}" num_s=" ") mlabposition(3) mlabgap(*10) mlabsize(3) mlabel(cond(@pval<.01, string(@b,"%9.3f") + "***", cond(@pval<.05, string(@b,"%9.3f") + "**", cond(@pval<.10, string(@b,"%9.3f") + "*", string(@b,"%9.3f"))))) msize(large) legend(off) note("*** p<0.01, ** p<0.05, * p<0.10")
    graph  export first_birth.png, width(1000) replace
    All of the variables are categorical (except for the "number of siblings" which I treat as continuous) and specific values are labeled. The problem is that the first time I generated a plot using this code, I got:
    Click image for larger version

Name:	first_birth.png
Views:	1
Size:	126.4 KB
ID:	1609942

    which is the outcome that I want. However, I made a spelling mistake, so I wanted to correct it. After opening my syntax the next day and running THE SAME code I got:
    Click image for larger version

Name:	first_birth_1.png
Views:	1
Size:	117.6 KB
ID:	1609943


    So it appears that coefplot reads only the label for "numer of siblings" and not for the other variables and it also drops headlines.
    I have no idea why it is so. Please help me if you have a clue.

    Regards,
    Honorata
    Last edited by Honorata Bogusz; 16 May 2021, 11:37.

  • #2
    Ok, I know the answer after a lot of trial and error but I do not understand it. For some reason, when I run:

    Code:
        logit child1 int_1-int_8 cohort_1-pgemplst_8 i.edu_level i.married i.pgemplst i.cohort  num_s, cluster(pid) nolog or
    without "xi: asdoc" or "xi:", coefplot displays the right labels. Still, if someone knows the answer why it is so, I'll be happy to hear an explanation.

    Comment


    • #3
      The xi prefix is outdated syntax. If you type help xi and scroll down a few lines in the output, you will see the following.
      Code:
          +-----------------------------------------------------------------+
          | Most commands in Stata now allow factor variables; see          |
          | fvvarlist. To determine if a command allows factor variables,   |
          | see the information printed below the options table for the     |
          | command.  If the command allows factor variables, it will say   |
          | something like "indepvars may contain factor variables."        |
          |                                                                 |
          | We recommend that you use factor variables instead of xi if a   |
          | command allows factor variables.                                |
          |                                                                 |
          | We include [R] xi in our documentation so that readers can      |
          | consult it when using a Stata command that does not allow       |
          | factor variables.                                               |
          +-----------------------------------------------------------------+
      So your version of Stata is new enough that your i. variables were interpreted as factor variables and the xi: was unneeded.

      See help fvvarlist for details.

      Comment


      • #4
        Thank you! That explains it.

        Comment

        Working...
        X