Statalist The Stata Listserver

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

Re: st: Dropping Subset of Variables

From   "Neil Shephard" <>
Subject   Re: st: Dropping Subset of Variables
Date   Thu, 29 Mar 2007 13:50:36 +0100

Unless you are hitting memory issues in Stata there's no real
advantage to dropping out variables (although I guess you may be
preparing data to pass on to someone else).

So onto the problem, and hopefully a solution (although it may not be
very elegant).

You've a set of variables all beginning with 'hv' and ending with
_02..._46 that you wish to drop.

One possible option might be to -reshape- your data and then -drop-
variables and then observations -if()- a condition is met, but that's
likely to take some time given the number of variables your

One solution might be to use two loops...

forval x = 2/9{
 drop hv*_0`x'
forval x = 10/46{
 drop hv*_`x'

(NB - My previous suggestion had invalid syntax because I had used
'in' which is used with -foreach- which is what I get for typing too
quickly and not re-reading my post before sending it).

The above isn't elegant, but should drop out the variables that you
want to get rid of.


"Every great advance in natural knowledge has involved the absolute
rejection of authority."  - Thomas H. Huxley

Email - /
Website -
Photos -
*   For searches and help try:

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