Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Calculating percentages (proportions) of indicator variables
From
Abhimanyu Arora <[email protected]>
To
[email protected]
Subject
Re: st: Calculating percentages (proportions) of indicator variables
Date
Mon, 9 Aug 2010 15:15:28 +0200
I am sure there must be better ways. But one long tedious way could be to
-generate 4 (indicator) variables for each response
-by country generate total for each response corresponding to the
above variables, lets say bi (i=1-4)
-generate total obs var for each country bys country:gen new_var=_N
-and within a forvalues loop (i=1/4)
generate percentage_share=bi/new_var if response==i
On Mon, Aug 9, 2010 at 2:39 PM, <[email protected]> wrote:
> 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/