Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Destring and split variable


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
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
[email protected]


On 3 May 2013 13:46, Federico Belotti <[email protected]> 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: [email protected]
> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index