Statalist The Stata Listserver


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

Re: st: A calculation problem


From   "Jia Xiangping" <jiajoseph@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: A calculation problem
Date   Tue, 26 Sep 2006 05:43:43 +0800

Dear Philipp,

Thank you for your kind attention. But I do not think you understand
the data very well, or  probably the way I explain. The p25 is not the
price for one specific crop. It is related to v25. What is more, the
price of one crop, say 01, is not necessarily in one price variable.
Again, for example, the price of crop 01 also appear in p51, which
corresponds to v51 in obs 4.

What's more, egen mean() seems to be OK. But I am doubting if it can
deal with the missing case.

Anyway, thank you again.


On 9/26/06, Philipp Rehm <Philipp.Rehm@gmx.de> wrote:
There are various ways to do this, I believe.
One option may be:

egen mean_p25=mean(p25)

If you have lots of prices to calculate, you may want to work with a
loop, perhaps along the following lines:

foreach var of varlist p* {
egen mean_`var' = mean(`var')
}

Depending on what you want to do next, you could also collapse the data
set (type "help collapse").

HTH,
Philipp


Jia Xiangping wrote:
> Dear friends,
>
> I have been annoyed by one problem for several days, and I am unable
> to work it out. Sincerely wish you can give me a hand. I believe after
> suffering from this, I can expect some improvement.
>
>
> obs v25 v38  v51 v64 p25  p38  p51  p64
> 1    01   12  39        0.7   1.8   0.6   0.5
> 2    01   19  21         .     1.6   0.8   0.7
> 3    01   34  19        0.6   .      0.6    0.7
> 4    09   19  01        1.5   0.9   0.9
> 5   19    25  07
> 6   12    31
> 7   25
>
>
>
> While v25 v38 v51……stand for the code of different crops, p25 p38
> p51…stand for the correspond price. Things become remarkably tricky
> when some price are missing. For example, crop 01 has price 0.7 in
> observation 1, but price is missing in observation 2.
>
> Now I want to calculate the average price of different crops. Is that
> possible? I am now like an ant on hot brick.
>
>
*
*   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/


--
Xiangping JIA

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index