Statalist


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

st: RE: Counting commas in a string variable


From   PEREZ PEREZ JORGE EDUARDO <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Counting commas in a string variable
Date   Fri, 3 Jul 2009 03:17:19 +0000

Not really an elegant solution, but it works

preserve
split var1, parse(,)
drop var1
foreach x of varlist _all {
replace `x'="1" if `x'!=""
}
destring _all, replace
egen count=rowtotal(_all)
replace count=count-1
keep count
tempfile count
save `count'
restore
merge using `count'
drop _merge

______________________
Jorge Eduardo Pérez Pérez

-----Mensaje original-----
De: [email protected] [mailto:[email protected]] En nombre de [email protected]
Enviado el: jueves, 02 de julio de 2009 09:48 p.m.
Para: [email protected]
Asunto: st: Counting commas in a string variable


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.

Can anyone help with this?

Thanks,
Conor
*
*   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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index