Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: extract data points from series


From   n j cox <[email protected]>
To   [email protected]
Subject   Re: st: extract data points from series
Date   Mon, 02 Apr 2007 12:32:59 +0100

You have about 17 years' worth of monthly data. I am not so clear
that this is too much to plot intelligibly, but I'll answer your
question first.

What you are doing can be compressed. First,

. gen tmp1 = string(year)
. gen tmp2 = real(tmp1)

is just getting -real(string(year))-, which is -year- in disguise.

. gen tmp3 = tmp2 if (int(tmp2/12)==tmp2/12)

could thus be

. gen tmp3 = year if (int(year/12) == year/12)

but you don't need any new variable to do what you you want:

. twoway (connected xxx year, msymbol(O)) if (int(year/12) == year/12)

is exactly equivalent. The -format- statement is thus unnecessary too.

From your example, it seems your -year- is not always integers. This
example shows how you get most flexibility if your time variable is
integer-valued:

. use http://www.stata-press.com/data/r9/air2.dta
(TIMESLAB: Airline passengers)

. tsline air if mod(t, 12) == 1

The trick for flexibility is to use -mod(,)- with integer arguments.
-mod(<timevar>, <spacing>) == <start>- gives you the choices you want.
-mod(<timevar>, 4)- selects quarterly for example.

There is more on -mod(,)- at

SJ-7-1 pr0031 . Stata tip 43: Remainders, selections, sequences, extractions
Q1/07 SJ 7(1):143--145 (no commands)
tip for uses of the modulus

Now back to your main question:

1. If you think short-term variation is basically noise, you can still use a smoother such as -lowess- to see patterns or trends and treat the data as backdrop.

2. There might still be some seasonal structure to what you are suppressing. See

SJ-6-3 gr0025 . . . . . . . . . . . . Speaking Stata: Graphs for all seasons
Q3/06 SJ 6(3):397--419
illustrates producing graphs showing time-series seasonality

The main commands discussed there, -cycleplot- and -sliceplot-, are downloadable regardless of whether you have access to the printed Stata Journal.

Nick
[email protected]

d.cyril

I've been using Stata for some time now but still don't find myself
native when it comes to data manipulation. Wonder if you could affirm
the method I used and suggest possible extension.

Consider, you have few time-series - with var year [1970m01-2007m01]
(%tm) - and you want to plot a basic tsline (read twoway connected)
with markers. Because there are so many observations in the data set,
the plot doesn't look adequate. Since, short-term dynamics don't
matter too much I decided to take first month observation for each
year using:

-------------------------------------------
. tsset year
. gen tmp1 = string(year)
. gen tmp2 = real(tmp1)
. gen tmp3 = tmp2 if (int(tmp2/12)==tmp2/12)
. twoway (connected xxx year, msymbol(O)) if tmp3 !=.
. format tmp3 %tm
-------------------------------------------

It works alright but would it be the best way of doing it? Since it
clearly only works for the 1st month of each year, another question
begs to be answered - how would you perform the same task with
quarterly/half-year data points to increase precision?

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index