Statalist


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

Re: st: keep


From   "Sergiy Radyakin" <serjradyakin@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: keep
Date   Mon, 10 Sep 2007 16:14:32 +0200

Hi,
alternatively this is an option too:
**---------------------------------------------------------------------
local keeplist "v1 v2 v3"
quietly ds_util
local dsv `r(varlist)'
drop `:list dsv - keeplist'
**---------------------------------------------------------------------

or here is one more:
**---------------------------------------------------------------------
capture gen v1=.
capture gen v2=.
capture gen v3=.
keep v1 v2 v3
**---------------------------------------------------------------------


Best regards,
   Sergiy Radyakin

On 9/10/07, Erik Bihagen <erik.bihagen@sofi.su.se> wrote:
> Thanks Sebastian, it works!
>
> Erik
>
> Sebastian F. Büchte wrote:
> > Erik
> >
> > in deed I guess you are right. So my suggestions would now involve a
> > little programming:
> >
> > *----- example start
> > //local keeplist holds the list of variables which you would like to
> > keep if they
> > //exist in the dataset
> > local keeplist v1 v2 v3
> >
> > local kl_modif
> > foreach el of local keeplist {
> >       capture confirm variable `el'
> >       if _rc==0 {
> >               local kl_modif `kl_modif' `el'
> >       }
> > }
> > capture keep `kl_modif'
> >
> > *-----example end
> >
> > 2007/9/10, Erik Bihagen <erik.bihagen@sofi.su.se>:
> >
> >> Thanks,
> >>
> >> but i tried that. The problem is that the result of -capture keep v1 v2
> >> v3 -  is that the command is disregarded. As an example; I want to keep
> >> v1, and v2, but not v4 for data sets where v1, v2 and v4 are present
> >> (and run the same command for all other data sets I have, see below)
> >>
> >> /Erik
> >>
> >> Sebastian F. Büchte wrote:
> >>
> >>> Erik
> >>>
> >>> try -capture keep v1 v2 v3-.
> >>>
> >>> regards
> >>> Sebastian
> >>>
> >>> 2007/9/10, Erik Bihagen <erik.bihagen@sofi.su.se>:
> >>>
> >>>
> >>>> 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.
> >>>>
> >>>> Cheers
> >>>>
> >>>> Erik
> >>>>
> >>>> --
> >>>> Erik Bihagen
> >>>> Swedish Institute for Social Research
> >>>> Stockholm University
> >>>> SE-106 91 Stockholm
> >>>> Phone: +46 8 16 26 51
> >>>> Fax: +46 8 15 46 70
> >>>>
> >>>>
> >>>> *
> >>>> *   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/
> >>>>
> >>>>
> >>>>
> >>> *
> >>> *   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/
> >>>
> >>>
> >>>
>
>
> *
> *   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/
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index