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

st: substring


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: substring
Date   Mon, 17 May 2004 20:01:55 -0500

-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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of umit ozmel
Sent: Tuesday, May 18, 2004 5:20 PM
To: statalist@hsphsun2.harvard.edu
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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index