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]

Re: st: Variables loop and deletion under certain conditions


From   Chris Parker <cparker.phd2007@london.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Variables loop and deletion under certain conditions
Date   Fri, 13 May 2011 01:44:59 +0100

Thanks Eric, I didn't even know about -ds-. That should help me in
some of my analysis.

Chris

Chris Parker

________________________________

PhD Candidate | Management Science & Operations
London Business School | Regent's Park | London NW1 4SA | United Kingdom
Direct line +44 (0)20 7000 8816 | Email cparker.phd2007@london.edu

On Thu, May 12, 2011 at 6:32 PM, Eric Booth <ebooth@ppri.tamu.edu> wrote:
>
> <>
>
> Chris could also use -ds- to filter his varlist to string variables only if that is a concern -- but that wasn't a part of the question.
> Further, Daniel's example has an error - it should read:
>
> *****
> foreach varname of varlist v* {
>       cap conf str v `varname'    //fixed
>       if _rc continue
>        if `varname'[5]=="#ERROR" drop `varname'
> }
> *********
> - Eric
>
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> ebooth@ppri.tamu.edu
>
> On May 12, 2011, at 12:17 PM, daniel klein wrote:
>
> > Eric already answerd the "why" it does not work. The solution proposed
> > by Chris should work. Erics solution (although it is more an example)
> > can be modified, because it will fail if the loop contains numeric
> > variables. I do not know whether skipping numeric variables will
> > additionally saves some execution time.
> >
> > ---code revised---
> > foreach varname of varlist v*{
> >        cap conf str v `v'
> >        if _rc continue
> >       if `varname'[5]=="#ERROR" drop `varname'
> > }
> > ---end---
> >
> > Best
> > Daniel
> > *
> > *   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/
>
>
>
> *
> *   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/
>
> ______________________________________________________________________
>
> This email has been scanned by the MessageLabs Email Security System
> on behalf of the London Business School community.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________

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