Statalist The Stata Listserver


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

Re: st: reshape, dropping empty variables


From   "Ada Ma" <[email protected]>
To   [email protected]
Subject   Re: st: reshape, dropping empty variables
Date   Wed, 3 May 2006 18:26:45 +0100

I think since you have those variables created when you reshape the
data to wide, then you must have at least one observation in those
variables, and they wouldn't be "empty" as you said??

If you really want to check and drop you can do a loop, e.g. if your
new variables are all named something2002 something2005, etc., you
can:

ds something*

foreach v of varlist `r(varlist)' {
cap tab `v'
if r(N)==0 {
drop `v'
di "`v' is being dropped"  /* for you to keep track of what is dropped */
}
}



On 5/3/06, daphna bassok <[email protected]> wrote:
Hi-

I am having a bit of challenging time with the reshape command in
stata, and was hoping someone had some advice.

I have 8 years of data, and it is currently in long format. I have a
large number of variables in the dataset.  Some of the variables have
data for all eight years, but many have data only for 2002-2005  or
alternatively only for 1998-2001.  Therefore, when I reshape the data
from long to wide, I end up with a huge number of "empty" variables,
that have no values at all, and are therefore unnecessary.

I am looking for a way to drop all these empty variables, without
inspecting one at a time.

Is there a quick way to do  this?

Any help would be greatly appreciated.

Daphna

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


--
Ada Ma
Research Fellow
Health Economics Research Unit
University of Aberdeen, UK.
http://www.abdn.ac.uk/heru/
Tel: +44 (0) 1224 553863
Fax: +44 (0) 1224 550926

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