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

st: string variables


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: string variables
Date   Mon, 17 May 2004 21:11:59 -0400

Umit said

I am trying to take the first two characters of a string variable using
substr command as below:

name2 = substr(name,1,2)

However I get an error message of " type mismatch". Any idea about how I can
handle this?
He did not indicate whether he was using Stata 7 or 8. I presume that there is a 'generate' in this statement. In Stata 8, one can get away with gen name2 = substr(name,1,2), but in Stata 7, one must say gen str2 name2 = etc. -- that is, you must declare the new variable of type string. Otherwise Stata thinks you are assigning a string to a (default) float, and objects. Stata 8 is smarter about that.

Kit

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