Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Montly data - remove month from x-axis and keep year only


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Montly data - remove month from x-axis and keep year only
Date   Mon, 10 Feb 2014 12:01:06 +0000

The underlying fallacy here is that changing the display -format- is
equivalent to changing the data to a different form.

If you have numbers that are Stata monthly dates then for dates like
Jan 2001 those numbers are like

. di ym(2001,1)
492

i.e. 500 or so as Stata works with an origin of January 1960

di ym(1960,1)
0

You have in effect told Stata to display those numbers as years and so
they are just shown as such.

di %ty 492
0492

The leading zero is just Stata doing what you told it, within a
convention of four-digit years. In other words, the underlying values
like 492 remain what they were.

Consider

. di %tmCY 492
2001

That's what you are seeking, i.e. telling Stata "it's a monthly date,
but I just want to see the years".

For the graphical problem here, the special twist is showing year
labels centrally placed, for which see an explanation in excruciating
detail

SJ-7-4  gr0030  . Stata tip 55: Better axis labeling for time points/intervals
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/07   SJ 7(4):590--592                                 (no commands)
        tip on labeling graphs for time points and time intervals

http://www.stata-journal.com/sjpdf.html?articlenum=gr0030

For a stern homily that changing the format only the format changes, see

SJ-12-4 dm0067  . . . . . . . . .  Stata tip 113: Changing a variable's format
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/12   SJ 12(4):761--764                                (no commands)
        discusses what changing a variable's format does and does
        not mean

NB: -twoway- is a command, not a function.

Nick
[email protected]


On 10 February 2014 11:36, Kathrin Jacobs <[email protected]> wrote:

> I have a time series plot that I constructed using the "twoway" function. My question is the following: I have monthly data, but I just want the year to show up in the x-axis.
> My time variable is formatted as %tmMon_CCYY.
>
> My x-axis currently looks like this: January 2000, January 2001, ..., January 2014 with minor ticks for the months
> I would like to have it labelled as 2000 2001,...,2014 centered over the minor ticks:
>
> |,,,,,,,,,,,|,,,,,,,,,,,|,,,,,,,,,,,|
>     2000         2001        2002
>
> I have tried various options, but if I add the %ty format, I have strange values (0480   0500   0520 ...)  instead of years on the axis
> tsline consumption xlabel(,format(%ty)) tmtick(##12)
> Does anyone know how to do this?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index