Statalist The Stata Listserver

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

st: data management - loop?

From   "Alexander Staus" <>
Subject   st: data management - loop?
Date   Mon, 21 May 2007 17:48:54 +0200

Dear Stata users,

in my panel dataset I want a dummy for the most occurred value in a variable.

e.g.  for a household a variable can take values from 1 to 250, value 15 is the most named
value in one household, so I want a dummy which is 1 when the household named 15
otherwise 0.

I have some idea but I'm lost in getting the proper loop:

tab var, gen(var)

 		forvalues i=1(1)250 {

 			bysort household: gen N_`i'=sum(var`i')
 			bysort household: replace N_`i'=N_`i'[_N]

* Now some loop for:

 	bysort hh: gen dummy=1 if N_1 > N_2 & N_1 > N_3  & N_1 > N_4 ********more
possible values from 1 to 250 but not every number is named*************  & var1 ==1

* here all other possibilities...

Some idea or an easier way?


*   For searches and help try:

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