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

Re: st: Computing averages per good per country


From   "Eric G. Wruck" <[email protected]>
To   [email protected]
Subject   Re: st: Computing averages per good per country
Date   Fri, 10 Dec 2004 10:55:13 -0500

I believe egen will tack on the average price to every observation.  Another way would be to use collapse as below:

. l

     +-----------------------------+
     |   article   country   price |
     |-----------------------------|
  1. | Article 1        FR      15 |
  2. | Article 1        FR      20 |
  3. | Article 1        UK      10 |
  4. | Article 1        UK      18 |
  5. | Article 2        UK      10 |
     |-----------------------------|
  6. | Article 2        UK      20 |
  7. | Article 1        US      10 |
  8. | Article 2        US      10 |
  9. | Article 2        US      15 |
     +-----------------------------+

. collapse (mean) price, by(country article)

. l

     +-----------------------------+
     |   article   country   price |
     |-----------------------------|
  1. | Article 1        FR    17.5 |
  2. | Article 1        UK      14 |
  3. | Article 2        UK      15 |
  4. | Article 1        US      10 |
  5. | Article 2        US    12.5 |
     +-----------------------------+

.
As you can see here, you wind up with only one observation per country/article pair.  You'd probably want to rename the variable price to be something like avg_price.  Statalisters: Is there a way to rename the variable as it is being created with collapse?

Eric



>Why not just use "egen"?
>
>bys country good: egen ave_price=mean(price)
>
>dave
>
>------------------------------------------------------------------------
>
>PhD student, Harvard Economics Department
>Phone: (O) 617-495-5634, (H) 617 - 493 - 1536
>Address: Currier Mail Center #554, Cambridge, MA 02138
>
>------------------------------------------------------------------------
>
>On Fri, 10 Dec 2004 [email protected] wrote:
>
>>
>> Dear all,
>>
>> I am looking for the easiest way to compute averages per good per country.
>> My a dataset looks about the following:
>>
>> Article 1	US	10
>> Article 1	FR	15
>> Article 1	FR	20
>> Article 1	UK	10
>> Article 1	UK	18
>> �
>> Article 2	US	10
>> Article 2	US	15
>> Article 2	UK	20
>> Article 2	UK	10
>> ...
>>
>> In other words, I have prices for different goods, originating from
>> different countries. I am interested in the average price for each of the
>> goods per country, i.e. the average price charged for article 1 in the US,
>> the average for article 1 in France, in the UK; similarly for article 2
>> etc. A complication is that for a number of goods I only have observations
>> for a subset of countries, and the number of observations varies good and
>> country (e.g. for article 1 I have, say, 5 observations from Greece, but
>> none from Italy, whereas for good 3 I have ten observations from Italy, but
>> none from the US or France).
>>
>> So far I've only been able to come up with relatively clumsy solutions, so
>> help is greatly appreciated,
>>
>> Philipp
>>
>>
>>
>> --
>> _____________________________________________________________________
>> Zon Gratis ADSL. De voordelen van gratis internet met de snelheid van
>> ADSL. Zonder abonnementskosten en zonder vast contract. Je betaalt
>> alleen voor de tijd online. Nu zonder aansluitkosten en met gratis
>> modem. Bestel snel op zonnet.nl.
>>
>> *
>> *   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/


-- 

===================================================

       Eric G. Wruck
       Econalytics
       2535 Sherwood Road
       Columbus, OH  43209

       ph:      614.231.5034
       cell:     614.327.4182		
       eFax:    614.573.6639
       eMail:   [email protected]
       website: http://www.econalytics.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