Statalist The Stata Listserver


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

st: RE: reshape, dropping empty variables


From   "Alex Ogan" <aogan@ArrowstreetCapital.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: reshape, dropping empty variables
Date   Wed, 3 May 2006 12:17:17 -0400

You might want something like:

ds 
foreach var in `r(varlist)' {
	capture confirm numeric variable `var'
	if _rc==0 {
		quietly sum `var'
		if r(N)==0 drop `var'
	}
}

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of daphna bassok
Sent: Wednesday, May 03, 2006 12:06 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: reshape, dropping empty variables

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/


This message is intended solely for the designated recipient(s). It may contain confidential or proprietary information and may be subject to confidentiality protections. If you are not a designated recipient, you may not review, copy, or distribute this message. If you receive this in error, please notify the sender by reply e-mail and delete this message. 

Arrowstreet Capital, L.P. is an Equal Opportunity Employer. 



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