Announcement

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

  • xlabel option of a twoway graph

    hello and thanks in advance for the help.
    I am having some issues in setting the xlabel option in a two-way graph. Specifically, i have a dataset whereby i would like to plot a numerical variable (y-axis) against a date variable (x-axis) at quarterly frequency. The sample period goes from 1972q1 until 2020q2. I would like to set a label for the x graph that plots dates every 4 years (so 16 quarters). For example, 1972q1, 1976q1 and so on.

    this is the code that i'm using:

    * Plot
    local options graphregion(color(white)) bgcolor(white) xtitle(Year) ytitle("Growth rate (log changes)") ///
    xscale(titlegap(0) outergap(0)lwidth(medthin) lcolor(black)) yscale(titlegap(1) outergap(0) lwidth(medthin) lcolor(black)) ///
    ylabel(, nogrid) xtick(,tlcolor(black) tlwidth(medthin)) ytick(,tlcolor(black) tlwidth(medthin)) ///
    legend( label(1 "Manufacturing Capacity") cols(1) ring(0) region(margin(zero) color(none)))

    local legend_sw legend(bplacement(sw))
    local legend_US `legend_sw'
    local fc_xlabel_US xlabel(1972q1(16)2020q1)


    bgshade date, shaders(recessions) ///
    twoway ((line dCAPGMFA date, lcolor(black) lpattern(solid) lwidth(thick)), `fc_xlabel_US' ///
    `options' `legend_`US'')
    graph export "$export_directory\capacity_level_US.eps", replace


    However, I do receive the error:
    invalid label specifier, : 1972q1(16)2020q1:
    r(198);

    The variable date has already a format %tq.

  • #2
    As Stata dates are SIF values, the human-readable dates are not directly understood by the software. For this reason, you have convenience functions. In this case, see

    Code:
    help tq()
    So you want:

    Code:
    xlabel(tq(1972q1) (16) tq(2020q1))

    Comment


    • #3
      thanks for the answer.
      However, i still receive the same error:

      invalid label specifier, : tq(1972q1) (16) tq(2020q1):

      Comment


      • #4
        You may need to force evaluate the functions within -xlabel()-. Try:

        Code:
        xlabel(`=tq(1972q1)' (16) `=tq(2020q1)')

        Comment


        • #5
          i don't know why, but now it works.
          thank you a lot

          Comment

          Working...
          X