Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Handling string data

From   "Svend Juul" <SJ@SOCI.AU.DK>
To   <>
Subject   Re: st: Handling string data
Date   Mon, 31 Jul 2006 13:09:53 +0200

Subject   st: Handling string data
Date   Sun, 30 Jul 2006 21:12:28 -0400

Mingfeng wrote:
I have tried to solve this myself with the reference, but no luck so
far.  My problem is to run a function on a string variable.  This is
the data that I have

Variable X:


I was tring to generate a dummy variable y=1 when x3 is contained in X
and 0 otherwise.  Is there a command to do this?


   help string function

will tell about string functions. You need strpos() (In Stata 8 the name
is index()). So you can:

   gen y= strpos(X,"x3")>0

Hope this helps


Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796

*   For searches and help try:

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