Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Collapsing Over Limited Set

From   Jason Hwang <>
Subject   st: Collapsing Over Limited Set
Date   Thu, 15 Sep 2005 15:11:58 -0400 (EDT)

Hi there,

I would really appreciate someone's help with this question.

I'm trying to generate a dataset of statistics by collapsing another
dataset, but each of the id's I'm collapsing by, I want to use every
observation in the dataset except the one for the id under consideration.
Would there be a way to do this?

For example, I have data of the form:

company	product markup
100	31	.3
100	55	.2
111	31	0
111	55	.1
120	31	.1
120	55	.1

Now I want to ask the question: for each company, calculate the average
markup of each product it produces, where the average is taken over all
companies that sell the product except the company itself. So I want to
end up with

company	product	averagemarkup
100	31	.05
100	55	.1
111	31	.2
111	55	.15
120	31	.15
120	55	.15

Obviously collapsing the data the standard way is not going to do this. I
need to do this for hundreds of thousands of observations (hundreds of
companies and thousands of products) so am looking for a way to do this
that would be relatively quick. I would be grateful for any suggestions.

Thanks very much.

*   For searches and help try:

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