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]

Re: st: question about calculating frequencies


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: question about calculating frequencies
Date   Sat, 27 Mar 2010 13:54:38 -0700 (PDT)

--- On Sat, 27/3/10, Ekaterina Hertog wrote:
> I have a dataset containing individuals and about 40
> variables representing their interest in various activities.
> Each interest variable has a value of 1, 2 or 3 depending on
> the strength of interest expressed. I need to calculate
> numbers of men and women who expressed interest level 1 for
> each activity and then incorporate them as constants into my
> dataset.

*----------------- begin example -------------------
clear
input id sex int_baseball int_music int_cinema
1    1           1        2    1
2    1           1        3    1
3    2           3        1    2
4    1           2        1    2
5    2           2        2    1
end

foreach var of varlist int_* {
	bys sex `var' : gen N`var' = _N if `var' == 1
	bys sex (`var') : replace N`var' = N`var'[1]
	replace N`var' = 0 if N`var' == .
}

list
*------------------ end example ------------------------

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------




      

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