Statalist


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

st: Frequency distribution using multiple loops


From   hmjc66 <[email protected]>
To   statalist <[email protected]>
Subject   st: Frequency distribution using multiple loops
Date   Fri, 29 Jun 2007 09:32:39 -0400

Hi,

I am trying to get a frequency distribution and have got this far.
Here's what I want to do:- (see program below)

1. I want the sum of the q`l' group (i.e. frequency) if it equals 1 or
2. (i.e. I want the total no of observations if q`l' equals 1 and if
q`l' equals 2).
2. For each q`k', I need the total no of obs of the q`l'. (i.e. For
q23, I need the total no of obs of q29, q30 and q31 for each group
(i.e. 1 and 2 as one group, 3 as one group, 4 as one group, and 5 as
one group)). Same way for q24 and q25.
3. I then want to tabulate the data (table showing the results). My
current tab command is wrong.
4. Is there a more efficient way to run this?

Thanks,

Hugh


local i=1;
while `i' < 4 {;
local j=1;	
while `j' < 6 {;
local k=23;
while `k' < 26 {;
local l=29;
while `l' < 32 {;
	count if q`k'==`i' & q`l'==`j';
	tab q`l' q`k';
local l = `l' + 1;
};
local k = `k' + 1;
};
	local j = `j' + 1;
	};
	local i = `i' + 1;
	};
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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