Statalist The Stata Listserver


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

st: RE: Handling string data


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Handling string data
Date   Mon, 31 Jul 2006 06:06:26 -0500

One way would be to use the string function -regexm-

For example:

. clear

. input str12  x

                x
  1. "x1,x2,x3"
  2. "x1,x3"
  3. "x2"
  4. "x1,x3,x4,x5"
  5. "x5,x6"
  6. end

. gen y = regexm(x, "x3")

. l

     +-----------------+
     |           x   y |
     |-----------------|
  1. |    x1,x2,x3   1 |
  2. |       x1,x3   1 |
  3. |          x2   0 |
  4. | x1,x3,x4,x5   1 |
  5. |       x5,x6   0 |
     +-----------------+

Scott


> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Mingfeng Lin
> Sent: Sunday, July 30, 2006 8:12 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Handling string data
> 
> Greetings!
> 
> 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:
> 
> x1,x2,x3
> x1,x3
> x2
> x1,x3,x4,x5
> x5,x6
> 
> 
> 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?
> 
> Thanks!
> 
> Mingfeng



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