Statalist


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

Re: st: function to calculate frequencies


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: function to calculate frequencies
Date   Mon, 6 Oct 2008 07:55:28 +0100 (BST)

--- Javier L�zaro <[email protected]> wrote:
> I am a beginner programmer of Stata, I am doing an ado file where I
> need to calculate a determined frequency, but I can�t use the command
> "tabulate" (it doesn�t give me exactly what I want).
> For example, I would like to obtain the frequency for a variable of a
> number that, perhaps, there aren�t any observation. ( I can�t achieve
> it with tabulate, because it returns only the existing frequencies).

If you want to allow for the possibility that a category is empty then
you can't rely on the data to tell you which categories you should
compute the frequencies over. So you will have to specify the
categories. In that case -count- is the most basic command for
computing frequencies, see the silly example below. Alternatively, you
can take a look at Ben Jann's -fre- command, see -ssc describe fre-.

*---------------- begin example ----------------
sysuse auto, clear
foreach i in 0 1 300 {
	qui count if foreign == `i'
	di as text "`i' " as result r(N)
}
*----------------- end example -----------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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