Announcement

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

  • Coefplot: Labelling X-Axis on a Time Series

    This seems like it should have a simple answer, but I can't find it. I am struggling to label the x-axis the way I would like in coefplot, and have spent some time with documentation and previous posts without finding a satisfactory answer.

    I am using coefplot to plot mean healthcare visits (and CIs) in a population over time. This is complex survey data.

    First, I calculate means by year:

    Code:
    svy: mean providervisit, over(year)
    estimates store means
    Next, I use coefplot, using the rename option to rename my coefficients to display only the year (e.g. 1996, 1997, etc.), because otherwise they would be labelled "[email protected]" etc.

    Code:
     coefplot means, , vertical /// 
    rename(^.+@([0-9]+)\..+$ = \1, regex) nooffsets /// 
    recast(connected) cirecast(rcap) ytitle("Mean Annual Visits")
    The resultant plot (below) labels every individual year on the x-axis. However, I want to only show some years, say every 2 or so years (e.g. 1996, 1998, 2000, 2002, etc.). It would be of course easy to do this with twoway using xlabel, but I want to use coefplot rather than say collapse (mean) followed by twoway because this allows me to plot CIs with complex survey data. Does anyone know if this is possible?

    Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	37.7 KB
ID:	1762463

  • #2
    coefplot is from SSC, as you are asked to explain in FAQ Advice #12. You will likely still need to use -xlabel()- to exclude some years. Here is some technique:

    Code:
    local labels
    forval year= 1996(2)2021{
        local labels `labels' `=`year'-1995' "`year'"
    }
    
    coefplot means,  vertical ///
    xlab(`labels') nooffsets ///
    recast(connected) cirecast(rcap) ytitle("Mean Annual Visits")
    For your future posts, present a reproducible example as recommended in the abovementioned FAQ Advice.
    Last edited by Andrew Musau; 27 Aug 2024, 13:57.

    Comment


    • #3
      Hi Andrew, thanks a million for this recommendation, and will do so in future posts.

      Best,

      Adam

      Comment

      Working...
      X