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: RE: break string into multiple variables


From   "Sarah Edgington" <sedging@ucla.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: break string into multiple variables
Date   Wed, 10 Oct 2012 17:06:13 -0700

Sophie,
The easiest way to work with these might be to leave them as strings and use
substr function (-help substr- for more info) to pull out the answers from
each position.

One thing that will be important to consider is what happens when a question
isn't answered.  Your example only contains 10 places, which I assume is
because it's an artificial example and not because answers to 3 questions
are missing. However if missing questions are represented with a zero you'll
definitely want to work with the original string variables rather than using
destring to avoid losing leading zeros.
-Sarah

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Sophie Moullin
Sent: Wednesday, October 10, 2012 4:32 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: break string into multiple variables

Dear all,

I've got a number of string variables which contain answers for up to
13 questions within the broad variable category, which when destrung are
listed as one single numeric, e.g. 2222112222 (1 is yes, 2 is no).
I need to create separate variables for each question 1-13.

I haven't been able to find any example code for this on any of the stata
documentation or FAQ. Any advice would be much appreciated.

Many thanks,
Sophie
*
*   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/


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