Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

AW: st: Creating single characters from long strings


From   "Andri Rauch" <Andri.Rauch@insel.ch>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: Creating single characters from long strings
Date   Wed, 26 Mar 2008 14:13:27 +0100

Thanks Margret and Nick,
Your solutions work. Sorry Nick, it's not quite 500 characters. Actually its sequence data that I want to analyse position by position. 
Thanks Andri 

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Margaret R Grove
Gesendet: 26 March 2008 13:37
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: Creating single characters from long strings

Ah yes - early morning fog here!  No `j' needed.  Nick - I'm not sure what you mean about the length(variable) note.  I tried running that little program and it did what I wanted.

thanks,
Meg

Nick Cox wrote:
> For a string variable, -length(variable)- is equivalent to 
> -length(variable[1])-. That may or may not be a correct answer.
>
> Also `j' is the same as `i' here. 
>
> Nick
> n.j.cox@durham.ac.uk
>
> Margaret R Grove
>
> Andri,
>
> Perhaps something like this ....
>
> local len=length(variable)
> local j=0
> forval i=1/`len' {
>     local j=`j'+1
>     gen str1 var`j'=substr(variable,`i',1) }
>
> Meg
>
> Andri Rauch wrote:
>   
>> Dear all,
>> I should create single characters from very long strings (ie around
>>     
> 500
>   
>> characters).
>> My original variable abcdefg... should be transformed to:
>> variable_1: a, variable_2: b, variable_3: c, variable_4: d and so
>>     
> on...
>   
>> I assume it should be done by combining the substring and foreach 
>> command.
>>     
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>   

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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