[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: generate new variable with frequencies
At 13:42 4-11-2003, Matteo Foschi wrote:
If I understand correctly, you should just keep it more straightforward
using some of the -egen- functions (see -help egen-).
We have a little trouble with a, we think, easy task.
We want to generate a variable, which contains the relative frequency of
another variable values.
We have a variable, say "type", and want to built a new variable,
say "typ_freq", which shows the relatively frequency of each value of "type".
egen totalfreq = count(type)
bysort group: egen typfreq = count(type)
gen typfreq_rel = typfreq/totalfreq
This is if you have no weights. If you do have weights, the line of thought
is the same but you will have to play around with the other -egen- functions.
SEO Amsterdam Economics
University of Amsterdam
1018 WB Amsterdam
tel.:+ 31 20 525 1657
fax:+ 31 20 525 1686
A statistician: someone who insists
on being certain about uncertainty
* For searches and help try: