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]

st: RE: decompose string


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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 
n.j.cox@durham.ac.uk 

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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index