Statalist The Stata Listserver


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

RE: st: how does insheet determine datatypes?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: how does insheet determine datatypes?
Date   Sun, 7 Jan 2007 18:09:44 -0000

This particular problem can be avoided by using -capture-
as a prefix. 

capture ren `var' `=`var'[1]'

will eat the error if the first value is not a valid new 
variable name. Alternatively you could use -confirm-
directly. 

Nick 
[email protected] 

Phil Schumm
 
> If you want to avoid having to edit your data file(s), and assuming  
> the first row contains variable names each of which contains 
> at least  
> one non-numeric character, you can also simply use the -nonames-  
> option and then use something like the following:
> 
> 
>      foreach var of varlist _all {
>          ren `var' `=`var'[1]'
>      }
>      drop in 1
> 
> 
> Of course this will result in *all* your data being read as 
> strings.   
> However, this is sometimes desirable, as for example when you 
> need to  
> read and append several files and want to make certain that no data  
> are lost due to appending a numeric variable onto a string variable  
> (or vice versa).  In cases where this is not desirable, a 
> single call  
> to -destring- is all that is necessary to restore one or more  
> variables to numeric.
> 
> I mention this only because it raises two interesting questions (at  
> least to me).  First, note that the rename above will fail if the  
> original variable name (as appears in the first row of the 
> data file)  
> is not a valid Stata name.  

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