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 on April 23, and its replacement, is already up and running.

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

st: Save the percentage of each response category into new variables

From   <>
Subject   st: Save the percentage of each response category into new variables
Date   Fri, 9 Sep 2011 11:14:40 -0500 (CDT)

Hi all,

I have a panel data where I want to compare the percentage of people belonging to each category of the marital status variable in each group and each time point. There are five categories in the marriage variable and I have two time points and two groups each with say, 50 people.

Basically the question is how to save the output from "by time: tab marstat group" as percentages and into new variables.

The "collapse" function doesn't seem to have an option for calculating the percentage directly, so I did the following:

tab marstat, gen(marstat)

foreach v of varlist marstat1-marstat5{
replace `v'=. if `v'==0

collapse (count) marstat1-marstat5, by (group time)

foreach v of varlist marstat1-marstat5 {
gen `v'_pct=`v'/50

drop marstat1-marstat5

Is there a better way to achieve this? I need to do this for a huge dataset and I kind of feel there should already exist a way to do this kind of transformation. Thanks a lot in advance for your help!
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index