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

st: RE: RE: computing percentages


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: computing percentages
Date   Wed, 28 Apr 2004 16:01:07 +0100

Perhaps you want some aggregation 
as well, or to it by groups. Some techniques are 
shown by 

. count if hmsa_r == 2 
. local num = r(N) 
. count if inlist(hmsa_r,1,2,3) 
. local pc = 100 * `num' / r(N) 
. di `pc' 

That gives an overall percent. 

. bysort group : egen num = sum(hmsa_r == 2) 
. by group : egen den = sum(inlist(hmsa_r,1,2,3)) 
. gen pc = 100 * num / den 
. egen tag = tag(group) 
. tabdisp group if tag, cell(pc) 

That gives percents within -group-. 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 28 April 2004 15:52
> To: [email protected]
> Subject: st: RE: computing percentages
> 
> 
> Multiply by 100? 
> 
> Nick 
> [email protected] 
> 
> mertenmj
>  
> > I am using the following command:
> > 
> > g nonmetro=hmsa_r==2
> > 
> > g total=hmsa_r==1 | hmsa_r==2 | hmsa_r==3
> > 
> > gen pnonmetro=nonmetro/total 
> > 
> > I want the "pnonmetro" variable to be expressed in terms of 
> > percentage, from the resulting nonmetro/total. How do I do this?

*
*   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