[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: -word()- with non space separator

From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   st: -word()- with non space separator
Date   Wed, 23 Sep 2009 10:29:33 -0400

I have a dataset in which many variables are in
the most useless format imaginable. If a question
has multiple checkboxes as possible answers, the
response is stored as a string, with a number indicating
each box checked and these numbers separated by colons.


This variable takes 9 values, so I want to split into 9
different indicator variables, myvar_1-myvar_9, each
indicating whether that number was selected. -split()-
does not work, because of the differing number of values
per string. That is, it produces myvar_1 which equals "7"
for the last obs.

So I am looking for a way to check whether a given string
contains a given integer, which would allow me to

   forv i=1/9 {
	gen byte myvar_`i'= [`i' is in myvar list]

As long as there are just 9 values, I can use -strpos()-
to check for the presence of the digit, but some of my variables
run into tens and twenties, in which case eg searching for "1"
returns true even if there is only "11".

The only solutions I see are to first -split()- and
then check all the new indicators, or run through a series of
checks such as (matches "1:" but not ":1").  I don't like
either: Is there a direct way to check to see if a given integer
is in the list?

I think there may be a regex solution, but my Perl programming
days are so far behind me that I've not been able to come up
with one.


*   For searches and help try:

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