Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: do file: t-score, dfuller, to sw regress


From   steven quattry <sjq2102@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: do file: t-score, dfuller, to sw regress
Date   Thu, 9 Dec 2010 13:34:26 -0500

Hello Statalisters,

I am on a quest to create a do-file that would perform (1) bi-variate
regressions, sort by t-score, delete observations below a certain
threshold, and then (2) run Dickey-Fuller on the remaining set of
variables, list only those that pass a Dickey-Fuller test at the 1%
critical level, then (3) filter out any missing data in my dataset via
a filter and then, of the data that passes through these three, I am
looking to:


- sort the remaining variables by t-score, highest to lowest

- delete the variables that are not amongst the 72 highest t-score variables

- then run a sw regress with these 72 variables, sorted by t-score still



With the help of many on this listserv, I have been able to achieve
(1), (2) and (3) (code listed below in 2.1-2.2).  However currently I
am copying the output from (1)- (3) into excel, vlooking up the
t-scores, sorting by t-scores, and then pasting this back into my
do-file to do the sw regress (2.3 in code below).  I suppose I was
hoping to achieve some insight as to coding or possible help topics in
stata that would allow me to build this in as it would save me hours
of tedious work each day.  If anyone can suggest some code or at least
point me in the right direction of how I might learn to do this, I
would be very appreciative.



Thank you for your consideration,



-Steven





I am using Stata/SE 11.1 for Windows



* 2.1 T-test and Dickey-Fuller Filter



    drop if n<61



    tsset n

tempname memhold

    tempname memhold2

    postfile `memhold' str20 var  double t using t_score, replace

    postfile `memhold2' str20 var2 double df_pvalue using df_pvalue, replace



    foreach var of varlist swap1m-allocglobal uslib1m-infdify
dswap1m-dallocglobal6 {

        qui reg dhealth `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'

log on

    use t_score,clear

    gsort -t

    l

    use df_pvalue, clear

    l

log off

restore



* 2.2 Missing data Filter

preserve

    drop if n<61



    foreach x of varlist `mylist2' {

        qui sum `x'

            if r(N)<72 {

                di in red "`x'"

                drop `x'

            }

            else {

                local myvar "`myvar' `x'"

            }

    }



    sum date

    keep if date==r(max)



    foreach x of varlist `myvar' {

        if `x'==. {

            drop `x'

        }

        else {

            local myvar2 "`myvar2' `x'"

        }

    }

log on

d `myvar2'

log off

restore




* 2.3 Stepwise Regressions



preserve

    drop if n<61



    local x "Here is where I paste in variables after sorting by
t-score and keeping only 72 highest"





log on

    sw reg dhealth `x', pe(0.05)





vif

*
*   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   |   Site index