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]

st: RE: decompose string


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: decompose string
Date   Mon, 8 Mar 2010 18:06:20 -0000

I'd use names that make it explicit which character is included. 

forval j = 1/9 { 
	gen v1_`j'= substr(v1, `j', 1) 
} 

Nick 
[email protected] 

John Bunge

I have a string variable v1. It contains names, e.g. "James" or "Valentine". I want to decompose v1 into string variables v2, v3, v4, ... that each contains one letter of v1.

The result:

*-----------begin example------------

v1              v2   v3   v4   v5   v6   v7   v8   v9 v10

James         J     a     m     e     s

Valentine   V    a      l      e     n     t       i      n    e

*-----------end example------------


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index