Dear Jesper,
Thank you for your attention. Now I think probably I fail in
explaining the problem.
Your method is approaching what I need, as its taking missing into
consideration. But the p25 is not price variable for one specific
crop. It is related to v25. What is more, say, crop 01 can also be in
v51, with corresponding price 0.9 in p51, in obs 4.
If we imagine the data in table way, that would be more understandable:
v25 p25
v38 p38
v51 p51
vi={1.2....40), stand for the crop type
p is the price corresponding to the specific crop. But some people
fail to report the price. I am going to calculate the average price
for every crop :(
That is my pains. I wish it is "growing pains".
On 9/26/06, Jesper KjÃ¦r Hansen <kjaer.hansen@oncable.dk> wrote:
On 2006/09/25 Jia Xiangping [jiajoseph@googlemail.com] wrote:
> 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.
Assuming you want to replace your price variable with a mean
variable (constant over all obs.), Philipp's suggestion
> egen mean_p25=mean(p25)
is the way to go. Alternatively, if you want to replace the
missing values of a price variable with the mean of the non-
missing obs. of the same variable, you should:
foreach var of varlist p25 p38 p51 p64 {
sum `var' , meanonly
replace `var' = `r(mean)' if missing(`var')
}
Perhaps you could be more precise on what you want?
-- Jesper K. Hansen
*
* 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/