Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: question about egen

From   Shige Song <[email protected]>
To   [email protected]
Subject   st: question about egen
Date   Thu, 17 Apr 2003 18:33:37 -0700

Dear All,

I am trying to use "egen newvar = count()" to generate a set of variables indicating frequency of old variables. The syntax is (as stated in the Reference manual):

egen nwear = count(exp)

I was wondering what this "(exp)" means (there is no example for this particular type of egen).

For example, I have variable GENDER (1: men, 2: women), CITY(a, b, c,d,e,f). I want to generate variables that show 1) number of men in each city, 2) number of women in each city, and 3) total number of people in each city. So I type:

sort CITY
by CITY: egen nm=count(GENDER==1)
by CITY: egen nw=count(GENDER==2)
by CITY: egen np=count(GENDER)

Stata generates all three variables with complains, but surprisingly, all three new generated variables are exactly identical (all equal the total number of people)! Can anyone please give me a hand? Thank you very much!

Shige Song
Department of Sociology, UCLA

* For searches and help try:

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