motto0005 发表于 2012-12-26 03:31 
是的,但是如果农户不种wheat,他的wheat种植面积应该是0,但如果直接用stata的求均值命令,这个0就被忽略 ...
说说下面例子怎么错了
clear
input id str5 crop area
1 "wheat" 10
2 "wheat" 0
3 "wheat" 10
1 "rice" 50
2 "rice" 0
3 "rice" 10
end
list
bys crop:egen mean=mean(area)
list
. clear
. input id str5 crop area
id crop area
1.
. 1 "wheat" 10
2.
. 2 "wheat" 0
3.
. 3 "wheat" 10
4. 1 "rice" 50
5. 2 "rice" 0
6. 3 "rice" 10
7. end
. list
+-------------------+
| id crop area |
|-------------------|
1. | 1 wheat 10 |
2. | 2 wheat 0 |
3. | 3 wheat 10 |
4. | 1 rice 50 |
5. | 2 rice 0 |
|-------------------|
6. | 3 rice 10 |
+-------------------+
. bys crop:egen mean=mean(area)
. list
+------------------------------+
| id crop area mean |
|------------------------------|
1. | 3 rice 10 20 |
2. | 2 rice 0 20 |
3. | 1 rice 50 20 |
4. | 3 wheat 10 6.666667 |
5. | 2 wheat 0 6.666667 |
|------------------------------|
6. | 1 wheat 10 6.666667 |