Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: Extracting numbers from code


From   "sanja_lutzeyer@ncsu.edu" <slutzey@ncsu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Extracting numbers from code
Date   Mon, 12 Nov 2012 10:36:35 -0500

Good day.
I have received a dataset from a survey in which numerous questions
asked respondents to check all that apply.
As an example, one such question had 11 possible items that
respondents could check.
The data is coded in such a way that if a respondent checked item 2,
item 4, item 7, item 10 and item 11, then the response in the dataset
is coded 2471011.
I need to create dummy variables for each item. As such, I need to
create 11 dummy variables, which equal 1 if the respondent checked
that item.
The respondent above would have.
item1_dummy = 0
item2_dummy = 1
item3_dummy = 0.... etc.

Until now, I have only encountered questions with up to 5 items, in
which case I manually coded them in the following way.
gen item1_dummy = 0
replace item1_dummy = 1 if item == 1 | (item>= 10 & item<= 19) | (item
>= 100 & item <= 199) etc....
This is horribly inefficient though. Is there another, easier way to
do this? Is there a way to code something like
item2_dummy = 1 if item contains the number 2.
Any advice would be greatly appreciated.
Kind regards
Sanja
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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