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, statalist.org 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 <klein.daniel.81@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Extracting numbers from code
Date   Mon, 12 Nov 2012 17:12:36 +0100

Sanja,

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
respondent
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")

Best
Daniel
-- 
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
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