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

RE: st: Creating single characters from long strings

From   "Nick Cox" <>
To   <>
Subject   RE: st: Creating single characters from long strings
Date   Wed, 26 Mar 2008 12:10:36 -0000

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. 


Margaret R Grove


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)


Andri Rauch wrote:
> Dear all,
> I should create single characters from very long strings (ie around
> characters).
> My original variable abcdefg... should be transformed to:
> variable_1: a, variable_2: b, variable_3: c, variable_4: d and so
> I assume it should be done by combining the substring and foreach
> command.

*   For searches and help try:

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