Statalist


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

RE: st: function to calculate frequencies


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: function to calculate frequencies
Date   Mon, 6 Oct 2008 11:36:19 +0100

On -count- see also 

SJ-7-4  dm0033  . . . . . . Speaking Stata: Counting groups, especially panels
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/07   SJ 7(4):571--581                                 (no commands)
        discusses how to count panels through reduction commands
        or through tabulation commands and how to overcome
        problems that do not yield easily to these approaches

SJ-7-1  pr0029  . . . . . . . . . . . . . . .  Speaking Stata: Making it count
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q1/07   SJ 7(1):117--130                                 (no commands)
        discusses count used with a loop over observations
        or variables

Nick 
n.j.cox@durham.ac.uk 

Maarten buis

--- Javier Lázaro <javierlazaro9@gmail.com> 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 )


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index