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

AW: st: count same strings among variables

From   "Martin Weiss" <>
To   <>
Subject   AW: st: count same strings among variables
Date   Mon, 13 Jul 2009 17:54:33 +0200


 I think Antonio requested the number of matching strings in two string vars, so here is a modified version of Maarten`s code: 

sysuse auto, clear

clonevar make2=make
replace make="" in 2
replace make="" in 5
replace make="" in 22
replace make="" in 72
replace make2="" in 6
replace make2="" in 23

levels make
local levs "`r(levels)'"
levels make2
local levs2 "`r(levels)'"

/*same strings */ 
local levs3: list levs & levs2

di "number of strings " /* 
 */ "in make and make2 = " /* 
 */  `: word count `levs3''


-----Ursprüngliche Nachricht-----
Von: [] Im Auftrag von Maarten buis
Gesendet: Montag, 13. Juli 2009 17:39
Betreff: Re: st: count same strings among variables

--- On Mon, 13/7/09, Antonio Acconcia wrote:
> I have a number of variables, say x1-x10, with different
> number of observations all containing strings. I need to
> select those strings that (or simply to count how many
> strings) are present in x1-x2, x1-x3, and so on; how many
> are present in x2-x3, x2-x4, and so on ....but not in x1
> ..... The same string can appear at different lines (say
> observation 1 for x1 and observation 3 for x2).

levelsof x1
local levs "`r(levels)'"
levelsof x2
local levs "`levs' `r(levels)'"
local levs : list uniq levs
local k : word count `levs'
di "number of strings in x1 and x2 = " `k'

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


*   For searches and help try:

*   For searches and help try:

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