*! version 1.0.0 20nov1996 STB-34 sts12 program define wntestf version 5.0 local varlist "req ex min(1) max(1)" local in "opt" local if "opt" local options "Level(integer $S_level) SAving(string) t(string)" local options "`options' noGRaph T1title(string) XLAbel(string)" local options "`options' YLAbel(string) *" parse "`*'" tempvar touse mark `touse' `if' `in' markout `touse' `varlist' local samp "if `touse'==1" if "`t'" != "" { local targ ", t(`t')" } if `level'<10 | `level'>99 { local level 95 } quietly { _crcchkt `samp' `targ' * Sample is set and t variable verified to be good replace `touse' = . if `touse' == 0 sort `touse' `t' * Data now sorted so that sample is at top of dataset tempvar x gen double `x'=`varlist' `samp' * Uncomment when jwh fixes fft *tempvar xr xi count `samp' local N=_result(1) local samp "in 1/`N'" local n1=int(`N'/2)+1 tempvar w gen double `w'=((_n-1)/`N') in 1/`n1' * Problem with internal fft -- will be fixed * noi di in red "fft `x', gen(`xr' `xi')" * Fix this!! replace with tempvars when jwh fixes fft routine capture query born if _rc { local hasfix 0 } else { * Hope that query born saves date somewhere local hasfix 1 } local hasfix 0 if `hasfix' { tempvar xr xi fft `x' `samp', gen(`xr' `xi') } else { capture drop _xr _xi fft `x' `samp', gen(_xr _xi) local xr "_xr" local xi "_xi" } replace `xr'=0 in 1 replace `xi'=0 in 1 replace `xr'=sum(`xr'*`xr'+`xi'*`xi') local ss =`xr' in `n1' replace `xr'=`xr'/`ss' } label var `xr' "cumulative periodogram" label var `w' "frequency" qui replace `x'=. qui replace `x'=abs(`xr'-2*`w') in 1/`n1' qui sum `x' local stat=sqrt(`n1')*_result(6) qui bartcdf `stat' local pvalue=1-$S_1 * Add test in here and save results in the S_# macros if "`graph'" == "" { if "`saving'"!="" { local sarg ", saving(`saving')" } gph open `sarg' if "`t1title'"=="" { local t1title "Cumulative Periodogram White Noise Test" } if "`xlabel'"=="" { local xlabel "0,.1,.2,.3,.4,.5" } if "`ylabel'"=="" { local ylabel "0,.2,.4,.6,.8,1" } graph `xr' `w', s(i) xlab(`xlabel') ylab(`ylabel') `options' /* */ border t1("`t1title'") gphsave gph pen 2 tempvar size gen int `size' = 175 gphdt vpoint `xr' `w' `size' `samp' gphdt text 1 .25 0 0 $S_3 gph pen 1 gph pen 3 gphdt li 0 0 1 .5 local lev=`level'/100 bartq `lev' local sq1=$S_2/sqrt(`n1') local sq2=1.-`sq1' local sq3=`sq2'/2 local sq4=`sq1'/2 if "$S_OS" == "Unix" { gph pen 5 } else gph pen 4 gphdt line `sq1' 0 1 `sq3' gphdt line 0 `sq4' `sq2' .5 gph close } * Remove this when jwh fixes fft capture drop _xr _xi global S_1=`stat' global S_2=`pvalue' end