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: how to create a variable representing proportion and average for each id


From   Ulrich Kohler <kohler@wzb.eu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: how to create a variable representing proportion and average for each id
Date   Mon, 26 Sep 2011 08:59:58 +0200

. egen xpro = mean(x), by(id)
. egen yavg = mean(y), by(id)

Uli


Am Montag, den 26.09.2011, 11:10 +0900 schrieb fukugawa_nobuya:
> dear statalisters,
> is it possible to create a new variable like "xpro" shown below, which 
> represents each id's proportion of x==1?
> how about "yavg" shown below, which represents each id's average of y?
> 
> id	x	xpro	y	yavg
> 1	1	.667	2	2
> 1	0	.667	3	2
> 1	1	.667	1	2
> 2	1	.5	2	1
> 2	0	.5	0	1
> 3	0	0	0	0
> 
> thank you in advance.
> 
> --------------------
> FUKUGAWA Nobuya, Ph.D.
> Associate Professor
> Graduate School of Engineering
> Tohoku University
> http://sites.google.com/site/nfukugawa/
> 
> *
> *   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