-gen name2 = substr(name, 1,2)- would be an acceptable command if "name" is
a string variable. For example, using the auto data set
sysuse auto, clear
(1978 Automobile Data)
. gen name = substr(make, 1,2)
. l make name in 1/3
+--------------------+
| make name |
|--------------------|
1. | AMC Concord AM |
2. | AMC Pacer AM |
3. | AMC Spirit AM |
+--------------------+
It would appear that your variable name, however, is not a string variable.
You could -describe name- to see the storage type.
Scott
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of umit ozmel
Sent: Tuesday, May 18, 2004 5:20 PM
To: [email protected]
Subject: RE: handling date data (was st: Please help!)
Hi,
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?
Thanks
*
* 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/