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]

Re: st: Destring and split variable


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Destring and split variable
Date   Fri, 3 May 2013 13:50:23 +0100

I think this is riskier than what I proposed.

For example "1    5" is converted to "15".

The implication of the question is that position in string is
important, so that is not lightly discarded.
Nick
njcoxstata@gmail.com


On 3 May 2013 13:46, Federico Belotti <f.belotti@gmail.com> wrote:
> First, you have to remove internal blanks using the -subinstr()- function
>
> replace Variable1 = subinstr(Variable1," ","",.)
>
> Then, you can generate the new variables exploiting the -substr()- function
>
> gen newvar1 = substr(Variable1, 1,1)
> gen newvar2 = substr(Variable1, 2,1)
> gen newvar3 = substr(Variable1, 3,1)
>
> HTH,
> Federico
>
>
> On May 3, 2013, at 2:34 PM, André Gyllenram wrote:
>
>> Hello,
>>
>> I have a variable that looks like this:
>>
>> Variable1
>> 10305
>> 20607
>> 1 3 9
>> 1 4 5
>>
>> From this variable I want to create three new variables. The first one should be equal to the firs digit, the second should be equal to the third digit and the third should be equal to the third digit in variable1.
>>
>> I have tried to do this using the command destring and subinstr but i must do something wrong because it does not seem to work.
>>
>> Does anyone know how to do this?
>> *
>> *   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/
>
> --
> Federico Belotti, PhD
> Research Fellow
> Centre for Economics and International Studies
> University of Rome Tor Vergata
> tel/fax: +39 06 7259 5627
> e-mail: federico.belotti@uniroma2.it
> web: http://www.econometrics.it
>
>
> *
> *   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