Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: st: AW: Calculating percentages (proportions) of indicator variables


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: AW: Calculating percentages (proportions) of indicator variables
Date   Mon, 9 Aug 2010 17:10:31 +0200

<> 


"use *contract* for percentage calculation."



Quite right:

*************
clear*

inp byte(country response)
1 3
1 3
1 2
1 1
1 4
1 3
2 1
2 1
2 2
2 3
2 4
3 2
3 2
3 4
3 3
3 1
end

list, noo sepby(country)

contract country response
bys country: egen overall=total(_freq)
gen percent=100* _freq/overall
expand _freq
drop _freq overall
sort country response
l, noo sepby(country)
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Aravinda Meera Guntupalli
Gesendet: Montag, 9. August 2010 15:14
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: AW: Calculating percentages (proportions) of indicator variables

use *contract* for percentage calculation.

*************
h contract
*************


Aravinda

Martin Weiss wrote:
> <> 
>
>
>
> *************
> h collapse
> *************
>
>
>
> HTH
> Martin
>
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von rado645-bg@yahoo.de
> Gesendet: Montag, 9. August 2010 14:40
> An: statalist@hsphsun2.harvard.edu
> Betreff: st: Calculating percentages (proportions) of indicator variables
>
> Dear all,
>
> I hope that you would help me with the following technical problem.
>
>
> I have a dataset based on a question with four different possible answers. The 
> question takes the form of an indicator variable with 4 different numeric values 
> (1,2,3,4).
>
> I have data for individuals from several countries.  I need to generate a new 
> variable that contains the fraction (i.e. percentage share) of each response  to 
> the question within each country. However, I cannot find any online source on 
> calculating percentages with mutliple responses in Stata (more than two).
>
> Example:
>
> country: response:
>
> 1               3
> 1               3
> 1               2
> 1               1
> 1               4
> 1               3
> 2               1
> 2               1
> 2               2
> 2               3
> 2               4
> 3               2
> 3               2
> 3               4
> 3               3
> 3               1
>
>
>
> *
> *   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/
>
>
> *
> *   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/
>
>
>   


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


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