Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Dropping variables in regression equations based on R-Squared value |
Date | Sat, 20 Jul 2013 11:10:59 +0100 |
If there was a conflict with variable names if max(scalar(a), scalar(b)) > 0.95 local droplist `droplist' `x' } Nick njcoxstata@gmail.com On 20 July 2013 10:21, George Murray <george.murray16@gmail.com> wrote: > Thanks again for the help Nick. This worked, although I had to change > the scalar names. > > George. > > On Sat, Jul 20, 2013 at 5:12 PM, Nick Cox <njcoxstata@gmail.com> wrote: >> local droplist >> >> foreach x of varlist var1-var5000{ >> quietly reg `x' var5001 >> display "`x'" `e(r2)' >> scalar a = e(r2) >> quietly reg `x' var5002 >> display "`x'" `e(r2)' >> scalar b = e(r2) >> if max(a, b) > 0.95 local droplist `droplist' `x' >> } >> >> drop `droplist' >> Nick >> njcoxstata@gmail.com >> >> >> On 20 July 2013 07:45, George Murray <george.murray16@gmail.com> wrote: >>> abcde >>> Dear Statalist, >>> >>> I am running numerous regressions in the following form: >>> >>> foreach x of varlist var1-var5000{ >>> quietly reg `x' var5001 >>> display "`x'" `e(r2)' >>> quietly reg `x' var5002 >>> display "`x'" `e(r2)' >>> } >>> >>> Where e(r2) displays the R-Squared of each regression. >>> >>> If *either* of the above regression equations have an R-Squared >>> greater than 0.95, I want to drop the variable `x' . For example, if I >>> regress var500 on var1001, and then on var1002, and *either* of the >>> regressions have an R-Squared value over 0.95, I wish to delete >>> var500. >>> >>> Does anyone have a way of doing this? I’m doing this manually at the >>> moment, but is taking far too much time, and of course, it would be >>> better if I could find a way to do this with the code. >>> >>> Thank you. >>> >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/faqs/resources/statalist-faq/ >>> * http://www.ats.ucla.edu/stat/stata/ >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/statalist-faq/ >> * http://www.ats.ucla.edu/stat/stata/ > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/