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

# Re: st: Extracting numbers from code

 From Donald Spady To statalist@hsphsun2.harvard.edu Subject Re: st: Extracting numbers from code Date Mon, 12 Nov 2012 08:48:34 -0700

```I am not sure if this is what you want but one approach I have used is to assign values in the following way.
If you have 11 possible responses then
Response 1 = 1
Response 2 = 2
Response 3 = 4
Response 4 = 8
all the way up to
Response 11 = 2048

Thus if a person has responses 1 & 2, then they have a score of 3
if they respond to 1 & 4, then their score is 9 (basically) you sum the scores. Each sum is unique and from each sum you can determine exactly what a person responded to.
Thus if the score sum is 525, then they had responses equivalent to a score of 512 + 8 + 4 + 1; there is no other way to get a score of 525.

Does this help.

Don

On 2012-11-12, at 8:36 AM, sanja_lutzeyer@ncsu.edu <slutzey@ncsu.edu> wrote:

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

--

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