Statalist The Stata Listserver


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

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


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: how to create weight and aggregate data using the weight
Date   Wed, 17 Jan 2007 07:42:46 +0000 (GMT)

The weights you can make as follows:


*------------- begin example ------------
clear
input cat catid	str1 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
end

bys cat : gen w = 1/_N
list
*----------- end example -------------

You can look at the answer by Rajesh for the rest.

Hope this helps,
Maarten

--- "FUKUGAWA, N." <[email protected]> wrote:

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


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


		
___________________________________________________________ 
Yahoo! Messenger - with free PC-PC calling and photo sharing. http://uk.messenger.yahoo.com
*
*   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