Statalist


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

RE: st: Counting commas in a string variable


From   Roy Wada <roywada@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Counting commas in a string variable
Date   Thu, 2 Jul 2009 22:37:52 -0700

> I'm currently looking for some help generating a new variable that is a
> count of the number of commas in string variable in my data set. 
> 
> Conor

You can combine -length( )- and -subinstr( )- functions.
 
gen comma = length(trim(var1))-length(trim(subinstr(var1,",","",.)))
 
where var1 is the variable of interest.

Roy
 
_________________________________________________________________
Hotmail® has ever-growing storage! Don’t worry about storage limits. 
http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009
*
*   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   |   What's new   |   Site index