cls clear all set more off set graphics off set graphic on cd "X" ********************************************************************** quarterly //ssc install freduse freduse NAEXKP01GBQ652S UKNGDP GBRPFCEQDSMEI GBRGFCFQDSMEI GBRGFCEQDSMEI GBREXPORTQDSMEI GBRIMPORTQDSMEI BOERUKQ CCUSSP01GBQ650N CPALTT01GBQ659N LMUNRLTTGBQ647S gen y = yofd(daten) format y %ty gen q = qofd(daten) tsset q, quarterly gen Y = NAEXKP01GBQ652S gen C = GBRPFCEQDSMEI gen I = GBRGFCFQDSMEI gen G = GBRGFCEQDSMEI gen EX = GBREXPORTQDSMEI gen IM = GBRIMPORTQDSMEI gen UMP = LMUNRLTTGBQ647S gen FX = CPALTT01GBQ659N gen CPI = CPALTT01GBQ659N gen Rate = BOERUKQ gen ln_Y = ln(Y) gen ln_C = ln(C) gen ln_I = ln(I) gen ln_G = ln(G) gen ln_EX = ln(EX) gen ln_IM = ln(IM) sort y q drop if y <1960 generate t=tq(1960q1)+_n-1 format t %tq tsset t order t drop if y>2019 *********************************************************************lambda 1600 preserve foreach z in Y{ tsfilter hp ln_`z'_hp = ln_`z', smooth(1600) trend(ln_`z'_trend) #delimit ; graph twoway (line ln_`z'_hp t, lcolor(blue) lwidth(thick) lpattern(solid)), yline(0, lcolor(red) lpattern(dash)) tlabel(1960q1 1973q2 1979q4 1990q2 2008q1 2020q1) ytitle("") legend(on order(1 "`z'") cols(1) position(2) ring(0)) graphregion(color(white)) xtitle("") name(`z'_hp_all, replace); #delimit cr } foreach z in Y{ #delimit ; graph twoway (tsline ln_`z' , lcolor(blue) lwidth(thick) lpattern(solid)) (tsline ln_`z'_trend, lcolor(red) lwidth(midthick) lpattern(dash)), tlabel(1960q1 1973q2 1979q4 1990q2 2008q1 2020q1) ytitle("") title("`z'") legend(off) graphregion(color(white)) xtitle("") name(`z'_hp_trend, replace); #delimit cr } restore *****************************************************************lambda infinite preserve foreach z in Y { tsfilter hp ln_`z'_hp = ln_`z', smooth(1000000000) trend(ln_`z'_trend) #delimit ; graph twoway (line ln_`z'_hp t, lcolor(blue) lwidth(thick) lpattern(solid)), yline(0, lcolor(red) lpattern(dash)) tlabel(1960q1 1973q2 1979q4 1990q2 2008q1 2020q1) ytitle("") legend(on order(1 "`z'") cols(1) position(2) ring(0)) graphregion(color(white)) xtitle("") name(`z'_lin_all, replace); #delimit cr } foreach z in Y{ #delimit ; graph twoway (tsline ln_`z' , lcolor(blue) lwidth(thick) lpattern(solid)) (tsline ln_`z'_trend, lcolor(red) lwidth(midthick) lpattern(dash)), tlabel(1960q1 1973q2 1979q4 1990q2 2008q1 2020q1) ytitle("") title("`z'") legend(off) graphregion(color(white)) xtitle("") name(`z'_lin_trend, replace); #delimit cr } restore ******************************************************************************** *************************************************************** saving all plots set graphic on graph combine Y_hp_all, graphregion(color(white)) name(Y_hp_all, replace) graph export Y_hp_all.png, as(png) replace graph combine Y_lin_all, graphregion(color(white)) name(Y_lin_all, replace) graph export Y_lin_all.png, as(png) replace graph combine Y_hp_trend, graphregion(color(white)) name(Y_hp_trend, replace) graph export Y_hp_trend.png, as(png) replace graph combine Y_lin_trend, graphregion(color(white)) name(Y_lin_trend, replace) graph export Y_lin_trend.png, as(png) replace