Statalist The Stata Listserver


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

st: how to create weight and aggregate data using the weight


From   "FUKUGAWA, N." <[email protected]>
To   [email protected]
Subject   st: how to create weight and aggregate data using the weight
Date   Wed, 17 Jan 2007 14:48:19 +0900

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

table 1
cat	catid	x
1	24	a
1	73	a
1	6	b
2	108	c
2	12	a
3	67	d
4	41	c
4	9	d
4	103	b
4	85	c

weight is inverse of the number of "catid" within "cat".
the number of "catid" can be computed as follows.

. bys cat:count
-> cat = 1
    3
-> cat = 2
    2
-> cat = 3
    1
-> cat = 4
    4

then table 1 with weight will be as follows.

table 2
cat	catid	x	w
1	24	a	.33
1	73	a	.33
1	6	b	.33
2	108	c	.5
2	12	a	.5
3	67	d	1
4	41	c	.25
4	9	d	.25
4	103	b	.25
4	85	c	.25

finally i need to aggregated the data by x.

table 3
x	freq
a	1.166	(=.33+.33+.5)
b	.58	(=.33+.25)
c	1	(=.5+.25+.25)
d	1.25	(=1+.25)

how can i obtain tables 2 and 3?
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/



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