Oo笑容太甜oO/

stata滤波命令


tsset year
g GDPPRR=log(GDPPR)-log(GDPPR[_n-1])
// HP滤波
hprescott   GDPPRR ,stub(HP) smooth(6.25)
//BK滤波
bking  GDPPRR ,plo(2) phi(8) stub(BK) k(3)
//CF滤波
cfitzrw GDPPRR,plo(2) phi(8) stub(CF)
//移动平均
mvsumm  GDPPRR if year>1959,gen(SD_GDPPRR) window(5) stat(sd) end
mvsumm   CF_GDPPRR_1 if year>1959,gen(SD_CF_GDPPRR) window(5) stat(sd) end
twoway (line SD_CF_GDPPRR year if mod(year,5)==0) (connected SD_CF_GDPPRR year if mod(year,5)==0, mcolor(blue) msize(large) msymbo> l(circle))

stata 12版本以后新命令
Title

[TS] tsfilter -- Filter a time series, keeping only selected periodicities

Syntax

Filter one variable

    tsfilter filter [type] newvar = varname [if] [in] [, options]
Filter multiple variables, unique names

    tsfilter filter [type] newvarlist = varlist [if] [in] [, options]
Filter multiple variables, common name stub

    tsfilter filter [type] stub* = varlist [if] [in] [, options]
filter     Name                    See help for
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
bk         Baxter-King             tsfilter bk
bw         Butterworth             tsfilter bw
cf         Christiano-Fitzgerald   tsfilter cf
hp         Hodrick-Prescott        tsfilter hp
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
You must tsset or xtset your data before using tsfilter; see [TS] tsset and [XT] xtset.
varname and varlist may contain time-series operators; see tsvarlist.
options differ across the filters and are documented in each filter's manual entry.

Example

Setup
    . webuse gdp2

Use the Christiano-Fitzgerald filter to estimate the cyclical component of the log of quarterly U.S. GDP
    . tsfilter cf gdp_cf = gdp_ln

Plot the cyclical component