Statalist


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

Re: st: Function to identify data type


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Function to identify data type
Date   Tue, 26 Feb 2008 12:58:42 +0000 (GMT)

--- [email protected] wrote:
> I would like to generate new variables using this command:
> 
> for var  X1-X50 :replace X_new=1 if X=="New" 
> 
> But some Xi variables are numeric because empty
> 
> This command stops when one of the Xi is numeric 
> 
> How can I ask to execute this command only for string Xi variables ? 
> Is there a "format" function which returns the type of the variable ?
> If this exists, I could use:
> 
> for var  X1-X50 :replace X_new=1 if X=="New" & format(X)==string

gen byte X_new = 0
ds X1-X50, has(type string)
foreach var of varlist `r(varlist)' {
    replace X_new = 1 if `var' == "New"
}

Hope this helps,
Maarten



-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Inbox. http://uk.docs.yahoo.com/nowyoucan.html
*
*   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