Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AW: st: conditional "keep" statement
From
"Martin Weiss" <[email protected]>
To
<[email protected]>
Subject
AW: st: conditional "keep" statement
Date
Mon, 12 Apr 2010 17:12:59 +0200
<>
Robert`s approach will also be beneficial in terms of the size of David`s
dataset, since the "# of characters in a macro" is limited to as much as
1,081,511 if David uses the MP version. See -h limits-.
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Robert Picard
Gesendet: Montag, 12. April 2010 16:59
An: [email protected]
Betreff: Re: st: conditional "keep" statement
David,
You can build a new list that contains only existing variables by:
*--------------------------- begin example -----------------------
version 11
clear
sysuse auto
local myvars make bake price trunk turn shop
foreach v in `myvars' {
capture confirm var `v'
if !_rc local realvars `realvars' `v'
}
dis "`realvars'"
*--------------------- end example --------------------------
Robert
On Mon, Apr 12, 2010 at 9:54 AM, David Souther
<[email protected]> wrote:
> I'm combining (append & merge) hundreds of files which contain
> hundreds or thousands of variables each, and at each stage of the
> merge/append, I'd like to variables only if they are in a list that I
> specify.
> The issue is that not all of these datasets contain all the variables
> in this list. So, if I create a macro of my list,
>
> local myvars a1 a2 a3 d1 d2 d3
>
> and then specify,
>
> keep `myvars'
>
> in the loop for each combination of data, I get the error that some
> variable doesn't exist when it's not in the dataset. I tried getting
> around this with the -capture- command,
>
> cap keep `myvars'
>
> and using -ds-
>
> ds `myvars'
> keep `r(varlist)'
>
> or,
>
> ds `myvars', not
> drop `r(varlist)'
>
> and -ds- in combination with -capture- to no avail. Any other ideas
> (besides specifying the hundreds of variables to keep for each/every
> loop)??
>
> D.S.
> *
> * 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/
*
* 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/