Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: keep


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: keep
Date   Mon, 10 Sep 2007 08:02:31 -0400

..
Here's one way -- put a list of all variables in a local macro and your target list in another and use extended macro function to find their intersection:

unab allvars: _all
local include "v1 v2 v3"
local keepvars: list vars & include
keep `keepvars'

You could also use a foreach loop to construct the set the keep or drop.

Michael Blasnik

----- Original Message ----- From: "Erik Bihagen" <[email protected]>
To: <[email protected]>
Sent: Monday, September 10, 2007 7:09 AM
Subject: st: keep



Hi Statalisters,

Is there a way to let the keep command do the following?
I want to keep, let's say, three variables v1 v2 v3 before saving data, but all these three variables do not exist in all data sets for which I want to run the command (I want to do this with a loop using many data sets and I use global to define the variables).

I could drop variables instead using "capture drop v4" etc, but that would become a very long do file.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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