|From||Christopher F Baum <firstname.lastname@example.org>|
|Subject||st: string variables|
|Date||Mon, 17 May 2004 21:11:59 -0400|
I am trying to take the first two characters of a string variable usingHe 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.
substr command as below:
name2 = substr(name,1,2)
However I get an error message of " type mismatch". Any idea about how I can