Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Count presence of item on different vars

From   "Nikolaos A. Patsopoulos" <>
Subject   Re: st: Count presence of item on different vars
Date   Mon, 09 Oct 2006 18:37:41 +0300

Vimalanand S. Prabhu wrote:

This should work:

gen sum=0
forval i=1/146{
replace sum = sum+1 if v`i'=="4500"


Nikolaos A. Patsopoulos wrote:
Hi all,

I've got a set of variables v6-v146, each one containing string values (unique values ~4500):

v6 v7 v8 v9 v10...
text1 text1 text3 text45 text1...
text5 text2 text1 text455 text1

I want to count how many times each of the values appears in at least one of the v6-v146 in each row [observation], e.g. text1 appears at least once in 7365obs.

How can achieve this?


* For searches and help try:

Sorry, but it seems I failed to explain my problem sufficiently enough.

I want to create a new var (countAppear) that is going to hold the count of "appear at least once" of each unique value in the varlist v6-v146. Var v5 is the "primary" var that contains all unique values. Hence, if a value is not in v6 it will not be in the others as well. Lets say we have the value "text1" that appears 200 times at least once in the given varlist (v6-v146). So the value of the var countAppear for text1 will be 200 (int).

Hope its less confusing.


* For searches and help try:

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