// // Program: SB.do // Written by: Larry Taylor, June 2007 // Modified by: Joe Cardinale, Fall 2007 // // Purpose: Create a basis for business cycle turning point simulation // Creates 10 random cycle phases based off empirical termination probability // <10 since US business cycle has 10 cycles since WWII> // Creates variables, runs regression to find t-values for phase duration // Simulation run in conjuction with SBBOOT.do and SBIN.do // program define SB, rclass drop _all // // Run SBIN.do to pull in empirical results and run initial regression // SBIN // // Generates the starting variables // set more off set obs 1000 /*Sets a Maximum Sample Size */ gen Phase = 10 /*Number of Phases */ gen t = _n /*Equals the Observation Number */ gen u = uniform() /*Random Uniform[0,1] */ gen S = 0 /*Binary Dependent Variable */ gen DT = 0 /*Test Variable */ gen count = 0 /*Counts the Phases */ gen sampyes = 0 /*Determines the Sample Size */ gen durtest = 1 /*Tests number of phases generated */ // // Modify the data to identify the turning points // Repeat values returned from SBIN so they are available for all observations, // as they will be used in SBBOOT // replace prob = prob[_n-1] if t > 1 replace ttesthat = ttesthat[_n-1] if t > 1 replace S = 1 if u < prob replace DT = 1 if t == 1 replace DT = 1 if S[ _n-1] == 1 & t > 1 replace DT = DT[_n-1] + 1 if S[_n-1] == 0 & t > 1 replace count = 1 if t==1 & S == 1 replace count = count[ _n-1] + S[ _n] if t > 1 replace sampyes = 1 if count < Phase replace sampyes = 1 if count == Phase & S == 1 replace durtest = 0 if count >= Phase keep if sampyes /* removed if sampyes == 1 from egen, gen and regress */ // // Return the empirical t-ratio to SBBOOT // Generate invalid to test that simulation creates the expected number of phases // Value of invalid passed to SBBOOT, equals 0 if simulation is OK or a 1 if // simulation failed to produce enough phases // return scalar ttesthat = ttesthat gen invalid = durtest[_N] return scalar invalid = invalid // // Examine each phase in the simulation, test to ensure that each phase // has a value // ** Note i=1/10 due to 10 phases, must update this if you are simulating // a different number of phases // forvalues i = 1/10 { gen DT`i' = DT if S == 1 & count == `i' quietly summ (DT`i') return scalar dur`i' = r(max) drop DT`i' } // // The underlying regression to be used in simulation // regress S DT return scalar teststat = _b[DT] / _se[DT] // // Compress data -- allow Stata to optimize data storage to minimize size restrictions // quietly compress end