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: RE: How to identify patterns of cyclicality using STATA?


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: RE: How to identify patterns of cyclicality using STATA?
Date   Wed, 9 Nov 2011 10:32:41 +0000

The other part of Natasha's question was to identify periods of recovery. 

Y at the previous peak is 

gen ypp = y if peak 
replace ypp = ypp[_n-1] if missing(ypp) 

So the code should be something like 

gen recovery = 0 
replace recovery = cond(recovery[_n-1] == 0 & peak, 1, cond(recovery[_n-1] == 1 & (y >= ypp), 0, recovery[_n-1])) if _n > 1 

which can all be done panelwise. However, this is not tested. 

Nick 
[email protected] 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 09 November 2011 10:17
To: '[email protected]'
Subject: RE: st: RE: How to identify patterns of cyclicality using STATA?

Kit closed the thread, but I am going to open it again as Kit has not yet made his solution public and I have a corrected solution that may be of interest of others. 

We have an indicator -peak- for peaks and an indicator -trough- for troughs. 

Natasha pointed out that although a trough closes a phase, -sum(peak-trough) == 1- fails as a criterion for being in a phase because there can be one or more peaks between the peak starting the phase and the trough finishing it. She could have added, presumably, that there can be troughs before any peak that do not terminate a phase.  

Fair enough. Please consider 

gen phase = 0 
replace phase = cond(phase[_n-1] == 0 & peak, 1, cond(phase[_n-1] == 1 & trough, 0, phase[_n-1])) if _n > 1

So the rules are

1. Initialise to 0.

2. Change your mind if we are not in phase and this observation is a peak (we've started) 
_or_ if we are in phase and this observation is a trough (we've stopped). 

3. Phase is what it was previously otherwise. 

Note that the first observation needs care and that we can do this panelwise by prefixing 

by country:

Then I think it is over to spell machinery. 

Nick 
[email protected] 

Kit Baum 

As it happens I was able to consult with Natasha face-to-face this afternoon, and we came up with a workable strategy to deal with this and other complications that arose in discussing her needs. I will write up a stylized version of that solution as a Stata Tip. Please consider the thread closed.

Natasha Xingyuan Che

That was very helpful.  Thanks.  But here is one additional
complication in this specific example.  The cycles are not always in
symmetry, i.e., there are more peaks than troughs.  For example, the
two variables identifying peak and trough can look like this:

peak   trough
0            0
1            0
0            0
0            0
1            0
0            0
0            1
0            0
0            0

Now if I apply what you suggested: (gen period = sum(peak - trough)).
The variable "period" would be equal to 1 for the spell between 1st
and 2nd peak and the spell after the trough.  But the recession is
actually the spell between the 2nd peak and the trough, for which the
variable "period" would be equal to 2.

I think the bottom line is I need to identify only those peaks that
are followed by a trough in some future date.  Do you have any
suggestions on how to do that?  Many thanks!

Nick Cox 

> Check out
>
> SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying spells
>        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
>        Q2/07   SJ 7(2):249--265                                 (no commands)
>        shows how to handle spells with complete control over
>        spell specification
>
> and -tsspell- (SSC)
>
> for some Stata technique in this area.
>
> Your first question appears to be answered, at least roughly, by
>
> bysort country (time) : gen period = sum(peak - trough)
> tsspell , cond(period == 1)

Natasha Xingyuan Che

> I'm trying to identify business cycle peaks, troughs, and phases of
> recession and recovery in a panel data set of countries's quarterly
> output series.  I identified peaks and troughs, but am having trouble
> marking the periods in between (i.e., recessions and recoveries).  I
> would really appreciate it if any of you have suggestions about how to
> do this.
>
> The specific definitions of the variables are the following --
>
> A peak occurs at Quarter t of a time series of Y_t if:
> (Y_t - Y_t-1) > 0 and (Y_t - Y_t-2) > 0 and (Y_t - Y_t+1) > 0 and (Y_t
> - Y_t+2) > 0
>
> A trough occurs at Quarter t if:
> (Y_t - Y_t-1) < 0 and (Y_t - Y_t-2) < 0 and (Y_t - Y_t+1) < 0 and (Y_t
> - Y_t+2) < 0
>
> A "recession" is a phase from peak to the next trough.  A "recovery"
> is a phase from trough to the quarter when Y reaches the level of the
> previous peak.
>
> I generated two 0/1 variables, peak and trough, as the following --
>
> tsset country time
> gen peak=(lny>l.lny&lny>l2.lny&lny>f.lny&lny>f2.lny)
> gen trough=(lny<l.lny&lny<l2.lny&lny<f.lny&lny<f2.lny)
>
> Now I want to generate two variables marking the quarters when the
> economy is in recession and in recovery and calculate the respective
> duration of the two.  But I'm not sure how to proceed.  Again, all
> your inputs are very much appreciated.  Thank you so much for your
> help!

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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