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

st: RE: Re^2: string variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re^2: string variables
Date   Fri, 6 Dec 2002 15:34:11 -0000

Katsuhide Isa

> > By the way, 
> > it is not correct that string variables can't 
> > be used with -generate- or -rename- or -forvalues-, 
> > it just depends what you are trying to do. 
> 
> But, I'm afraid these string variables can't  be used with 
> -generate- or -rename- or -forvalues-, as far as my data 
> is concerned.
> 
> The relevant part of the data is as follows:
> 
> -----------------------------------
>                       storage  display     
> variable name   type     format      
> -----------------------------------
> _1              int    %8.0g                  
> _2              int    %8.0g                  
> _3              int    %8.0g                  
> _4              int    %8.0g                  
> _5              int    %8.0g                  
> _6              int    %8.0g                  
> _7              int    %8.0g                  
> _8              int    %8.0g                  
> _9              int    %8.0g                  
> _10             int    %8.0g                  
> _11             str15  %15s   
> ....
> 
> Given this structure, when  typed 'gen SQ11 = _11', or
> 'forvalues i = 1/11 {gen SQ`i' = _`i'}', Stata says,
> 'type mismatch r(109);'
> Maybe I did somehing wrong, but I don't know what the 
> cause is.

If you look carefully, you will see that _11 alone 
is string and cannot be used to create a numeric variable 
without using some function or command to extract 
numeric contents. So (e.g.) your loop will fail at _11. 

Nick 
[email protected] 
*
*   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