Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

[no subject]


You can use a macro extended function to set a macro equal to the type
of each variable in turn, and drop the ones whose type includes "str"
(to drop string variables):

drop _all
set obs 10
gen x=1
gen y="a"
gen str8 z="b"

foreach v of varlist _all{
	local t:type `v'
	di "`t'"
	if index("`t'", "str")~=0{
		drop  `v'

Jamie Griffin

>>> 09/14/05 6:36 pm >>>
I have a quick question about how to select variables by their format.

Suppose I want to drop (or rename, or do something else) with all 
string variables. Clearly, 
-drop if- doesn't work as that selects observations, not variables. 

The motivation for this question is that I want to collapse a whole 
dataset by some variable: 
collapse *, by(somevar)
Specifically, I want to get the mean of all numeric variables by 
somevar, and get the highest "value" in alphabetical order of the 
string variables by somevar. So if there is no way to do this in one go

using -collapse-, I would collapse separately for the numeric and the 
string vars, and for that purpose I need to find a way to select 
variables by their format.

Thanks for any guidance on this!

Tewodaj Mogues
Dept. of Agricultural and Applied Economics
University of Wisconsin - Madison
427 Lorch St. #317, Taylor Hall
Madison, WI 53706
*   For searches and help try:

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