Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Use varlabel in expressions


From   "Trelle Sven" <strelle@ctu.unibe.ch>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Use varlabel in expressions
Date   Fri, 23 Mar 2012 20:47:17 +0100

One possibility that should work (I acknowledge that I haven't tested it but it should give you the direction)
Sven

* ** code starts ** *
foreach var of varlist * {
 	local label: var label `var'
	local match = substr("`label'",1,3)
	if "`match'"=="na-" {
		drop `var'
	}
}
* ** code ends ** *



-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Marcelo Lafleur
Sent: Freitag, 23. März 2012 19:54
To: statalist@hsphsun2.harvard.edu
Subject: st: Use varlabel in expressions

I've had not luck with this and all references in this list point to use of value labels. 

My question is simple: How, if possible, to drop variables based on a prefix in their varlabels?

Examples:

... des  mv218 mv225 mv245 mv246

variable name       value label      variable label
----------------------------------------------------------------------------
mv218                                           number of living children
mv225                  mv225            na-current pregnancy wanted
mv245                                           women fathered children 
with
mv246                   mv246           na-married to mother when first 
child was born

(I edited the output a bit)


I want to drop mv225 and mv246 by testing that the variable label starts with "na-"

Having hundreds of variables in each dataset, it would be impractical to do by hand.

Any ideas?

Marcelo
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index