NBERCycles - Generates dummies for NBER Cycles

Use this forum to post complete RATS "procedures". Please be sure to include instructions on using the procedure and detailed references where applicable.

NBERCycles - Generates dummies for NBER Cycles

Postby TomDoan » Sat May 16, 2009 11:51 am

Updated 5 Feb 2010 to produce dummies for daily and weekly data as well as monthly or quarterly.

The following generates dummy variables based upon the NBER business cycle reference dates. Note that there's also an attachment that you can download directly:
nbercycles.src
(4.6 KiB) Downloaded 283 times


Code: Select all
*
* @NBERCycles(options) start end
* Generates dummy variables for quarterly, monthly, weekly or daily data
* based upon the NBER business cycle reference dates.
*
* Parameters:
*  start end    Range over which to define dummies [full data range]
*
* Options:
*  PEAKS=0-1 dummy which is 1 for cycle peaks
*  TROUGHS=0-1 dummy which is 1 for cycle troughs
*  UP=0-1 dummy which is 1 from trough date + 1 until next peak date
*  DOWN=0-1 dummy which is 1 from peak date + 1 until next trough date
*
* Revision Schedule:
*  05/2009 Written by Tom Doan, Estima
*  02/2010 Revised to allow for daily/weekly data
*
* Source:
* National Bureau of Economic Research, Inc.
* 1050 Massachusetts Avenue
* Cambridge MA 02138
* USA
* www.nber.org/cycles.html
*
* Example:
*
* cal(m) 1950
* all 2009:12
* @NBERCycles(peaks=peaks,troughs=troughs,up=ups,down=downs)
* graph(style=spike) 2
* # peaks
* # troughs
* graph 2
* # ups
* # downs
*
procedure NBERCycles start end
option series *peaks
option series *troughs
option series *up
option series *down
*
* These are month, year and quarter for the reference dates
*
fixed rect[int] NBERpeaks(33,3)
6    ,1857     ,2
10   ,1860   ,3
4   ,1865   ,1
6   ,1869   ,2
10   ,1873   ,3

3   ,1882   ,1
3   ,1887   ,2
7   ,1890   ,3
1   ,1893   ,1
12   ,1895   ,4

6   ,1899   ,3
9   ,1902   ,4
5   ,1907   ,2
1   ,1910   ,1
1   ,1913   ,1

8   ,1918   ,3
1   ,1920   ,1
5   ,1923   ,2
10   ,1926   ,3
8   ,1929   ,3

5   ,1937   ,2
2   ,1945   ,1
11   ,1948   ,4
7   ,1953   ,2
8   ,1957   ,3

4   ,1960   ,2
12   ,1969   ,4
11   ,1973   ,4
1   ,1980   ,1
7   ,1981   ,3

7   ,1990   ,3
3   ,2001   ,1
12   ,2007   ,4

fixed rect[int] NBERTroughs(33,3)
12   ,1854   ,4

12   ,1858   ,4
6   ,1861   ,3
12   ,1867   ,1
12   ,1870   ,4
3   ,1879   ,1

5   ,1885   ,2
4   ,1888   ,1
5   ,1891   ,2
6   ,1894   ,2
6   ,1897   ,2

12   ,1900   ,4
8   ,1904   ,3
6   ,1908   ,2
1   ,1912   ,4
12   ,1914   ,4

3   ,1919   ,1
7   ,1921   ,3
7   ,1924   ,3
11   ,1927   ,4
3   ,1933   ,1

6   ,1938     ,2
10   ,1945     ,4
10   ,1949     ,4
5   ,1954     ,2
4   ,1958     ,2

2   ,1961     ,1
11   ,1970     ,4
3   ,1975     ,1
7   ,1980     ,3
11   ,1982     ,4

3   ,1991     ,1
11   ,2001     ,4
*
local integer twodigits
local integer pslot lower upper
*
if 2:1-1:1==4
   compute pslot=3
else
   compute pslot=1
compute twodigits=(2:1-1:1<=12)
*
* Set dummy for peaks
*
if %defined(peaks) {
   set peaks start end = 0.0
   do i=1,%rows(NBERPeaks)
      if twodigits
         set peaks start end = peaks(t).or.t==NBERPeaks(i,2):NBERPeaks(i,pslot)
      else
         set peaks start end = peaks(t).or.t==NBERPeaks(i,2):NBERPeaks(i,1):1
   end do i
}
*
* Set dummy for troughs
*
if %defined(troughs) {
   set troughs start end = 0.0
   do i=1,%rows(NBERTroughs)
      if twodigits
         set troughs start end = troughs(t).or.t==NBERTroughs(i,2):NBERTroughs(i,pslot)
      else
         set troughs start end = troughs(t).or.t==NBERTroughs(i,2):(NBERTroughs(i,1)+1):1-1
   end do i
}
*
* Set dummy for up-cycles. Note that the logic here (and for the down
* cycles) uses the fact that the first trough is before the first peak
* in the dates.
*
if %defined(up) {
   set up start end = 0.0
   do i=1,%rows(NBERPeaks)
      if twodigits {
         compute lower=NBERTroughs(i,2):NBERTroughs(i,pslot)
         compute upper=NBERPeaks(i,2):NBERPeaks(i,pslot)
      }
      else {
         compute lower=NBERTroughs(i,2):NBERTroughs(i,1):1
         compute upper=NBERPeaks(i,2):(NBERPeaks(i,1)+1):1-1
      }
      set up start end = up(t).or.(t>lower.and.t<=upper)
   end do i
   *
   * If there is an extra trough, fill out an open-ended range
   *
   if %rows(NBERTroughs)>%rows(NBERPeaks) {
      if twodigits
         compute lower=NBERTroughs(i+1,2):NBERTroughs(i+1,pslot)
      else
         compute lower=NBERTroughs(i+1,2):NBERTroughs(i+1,1):1
      set up start end = up(t).or.(t>lower)
   }
}
*
* Set dummy for down cycles
*
if %defined(down) {
   set down start end = 0.0
   do i=2,%rows(NBERTroughs)
      if twodigits {
         compute lower=NBERPeaks(i-1,2):NBERPeaks(i-1,pslot)
         compute upper=NBERTroughs(i,2):NBERTroughs(i,pslot)
      }
      else {
         compute lower=NBERPeaks(i-1,2):NBERPeaks(i-1,1):1
         compute upper=NBERTroughs(i,2):(NBERTroughs(i,1)+1):1-1
      }
      set down start end = down(t).or.(t>lower.and.t<=upper)
   end do i
   *
   * If there is an extra peak, fill out an open-ended range
   *
   if %rows(NBERPeaks)>=%rows(NBERTroughs) {
      if twodigits
         compute lower=NBERPeaks(i,2):NBERPeaks(i,pslot)
      else
         compute lower=NBERPeaks(i,2):NBERPeaks(i,1):1
      set down start end = down(t).or.(t>lower)
   }
}
end
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Return to RATS Procedures

Who is online

Users browsing this forum: No registered users and 1 guest