Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: do file: sort by t, then give dfuller p-value, then corr?


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: do file: sort by t, then give dfuller p-value, then corr?
Date   Fri, 20 Nov 2009 14:57:32 -0600

On Thu, Nov 19, 2009 at 2:44 PM,  <sjq2102@columbia.edu> wrote:
> Hello,
>
> I am looking to create a do file that will perform a good bit of
> analysis at the bivariate level.  Thanks to the code prepared by John
> Merryman and guidance from Nick Cox, I was able to achieve the first part of
> this task (sorting by t-score) (see code prepared by Mr. Merryman below).
>
> Now, I would like to perform the same task, but drop all variables with a
> t-score below 1.70.  I would then like to take this subset of data and
> perform a dfuller test, with an output being the p-value, filter out those
> with a p-value greater than 1% and finally perform a correlation matrix on
> the remaining variables.
>
> Is this at all possible?  Ideally, the output would keep the t-score,
> dfuller, and corr matrix, however, if the output was simply the corr matrix,
> having filtered for a t-score greater than 1.7, a dfuller pvalue of 1% or
> less, that would suffice as well.
>

Below is an example you can adapt -- and it's Scott not John.

Scott


cd "C:/Documents and Settings/Scott_2/Desktop/trash"
sysuse auto,clear
gen t = _n
tsset t
tempname memhold
tempname memhold2
postfile `memhold' str12 var double t using t_score, replace
postfile `memhold2' str12 var2 double df_pvalue using df_pvalue, replace

foreach var  of varlist mpg-gear {
        qui reg price `var'
        matrix e =e(b)
        matrix v = e(V)
        local t = abs(e[1,1]/sqrt(v[1,1]))
		if `t' < 1.7 {
			drop `var'
		}
		else {
			local mylist "`mylist' `var' "
			post `memhold' ("`var'") (`t')
		}
}
postclose `memhold'

foreach l of local mylist {
	qui dfuller `l', lag(1)
	if r(p) > .01 {
		drop `l'
	}
	else {
		local mylist2 "`mylist2' `l' "
		post `memhold2' ("`l'") (r(p))
	}
}
postclose `memhold2'
keep `mylist2'
corr `mylist2'
save corr_var_list,replace
use t_score,clear
l
use df_pvalue,clear
l

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index