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.

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

From |
Nick Winter <njgwinter@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Extracting numbers from code |

Date |
Mon, 12 Nov 2012 11:01:17 -0500 |

foreach code in 01 02 03 04 05 06 07 08 09 10 11 { gen item`code'_dummy = strpos(originalvar,"`code'")>0 } Nick Winter On 11/12/2012 10:36 AM, sanja_lutzeyer@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/

**References**:**st: Extracting numbers from code***From:*"sanja_lutzeyer@ncsu.edu" <slutzey@ncsu.edu>

- Prev by Date:
**Re: st: Extracting numbers from code** - Next by Date:
**Re: st: Extracting numbers from code** - Previous by thread:
**Re: st: Extracting numbers from code** - Next by thread:
**Re: st: Extracting numbers from code** - Index(es):