Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: "table" command with weight


From   "Rajesh Tharyan" <[email protected]>
To   <[email protected]>
Subject   st: RE: "table" command with weight
Date   Tue, 16 Jan 2007 12:28:08 -0000

Hi,

One way to do it would be. 

. collapse (sum) weight, by(x)

However, this will alter the dataset in mem. So type preserve first.

You could also try 

. bysort x: egen sumweight=sum(weight)

This creates a new variable sumweight with the sum of the weights..

Hope this helps
rajesh


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of FUKUGAWA, N.
Sent: 16 January 2007 11:42
To: [email protected]
Subject: st: "table" command with weight 

dear all,
i need to aggregate the data using weight.

the original data
cat	catid	x	weight
1	1	a	.33
1	2	a	.33
1	3	b	.33
2	1	c	.5
2	2	a	.5
3	1	d	1
4	1	c	.25
4	2	d	.25
4	3	b	.25
4	1	c	.25

the aggregated data
x	freq
a	1.166(=.33+.33+.5)
b	.58(=.33+.25)
c	1(=.5+.25+.25)
d	1.25(=1+.25)

please note i need to create weight (the proportion within the
category) because it does not exist in the original data.
this is to avoid double counting.
the number of rows is 9m.
the number of variables is 100.
thank you in advance.
--
FUKUGAWA Nobuya, Ph.D.
[email protected]

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index