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 on April 23, and its replacement, is already up and running.

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

Re: st: Extracting numbers from code

From   daniel klein <>
Subject   Re: st: Extracting numbers from code
Date   Mon, 12 Nov 2012 17:12:36 +0100


Nick already made clear that our suggestions depend on certain
assumtions. From your original posting I assume

1. <item> is a numeric variable that records the items checked by each
2. checked items are recorded in consecutive manner (i.e. <item> will
allways look like 1234 not 2431)
3. there are only 11 items, numbered from 1, 2, ..., 11 without leading zeros.

Here is how you create the dummies for items 2-11

forv j = 2/11 {
    g byte dummy`j' = (strpos(strofreal(item), "`j'") > 0)

Create the dummy for item 1 as

g byte dummy1 = (substr(strofreal(item), 1, 1) == "1")

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.
Any advice would be greatly appreciated.
Kind regards
*   For searches and help try:

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