Hello,
I am relatively new to using formulas in Stata and I want to calculate the Simpson's Diversity Index (Simpson in 1949) for each household (see data below) if this is possible?. Any advice is greatly appreciated! The formula for the Simpson's Index is
Where:
input str14 HHID float Parcel_ID str20 Crop_name double(Quan_harvested Quan_sold)
"1013000204" 21 "" . .
"1021000108" 1 "Banana food" 48 0
"1021000108" 1 "Cassava" 3 0
"1021000113" 1 "Beans" 3 0
"1021000113" 1 "Dodo" 2 0
"1021000113" 1 "Dodo" 10 0
"1021000113" 1 "Maize" 1 0
"1021000113" 1 "Yam" 99999 .
"1021000408" 1 "Banana food" 99999 .
"1021000408" 1 "Beans" 2 0
"1021000408" 1 "Maize" 1 0
"1021000710" 1 "Banana food" 99999 .
"1021000710" 1 "Beans" 3.5 0
"1021000710" 1 "Maize" 60 0
"1021000807" 1 "Coffee all" 7 7
"1021000807" 1 "" . .
"1021000807" 2 "Banana food" 180 80
"1021000807" 2 "Banana food" 30 0
"1021000807" 2 "Banana food" 90 90
"1021000807" 2 "Cassava" 17 17
"102100080803" 1 "Banana food" 20 0
"102100080803" 1 "Coffee all" 0 .
"102100080803" 2 "Beans" 1 0
"102100080803" 2 "Maize" 1 1
"102100080803" 2 "Groundnuts" 2 0
"102100080803" 2 "Maize" 1 1
"102100080803" 21 "Cassava" 2 0
"102100080803" 21 "Maize" 2.5 1
"102100080803" 21 "Sweet potatoes" 1 0
"102100080803" 21 "" . .
"102100110201" 1 "Beans" 1 0
"102100110201" 1 "" . .
"102100110201" 2 "Cocoa" 4 4
"102100110201" 2 "Coffee all" 1 1
"102100110201" 2 "Groundnuts" 3 0
"102100110201" 3 "Groundnuts" 4 2
"102100110201" 3 "Beans" 1 0
"102100110201" 3 "Cassava" 99999 .
"102100110201" 4 "" . .
"1021001109" 1 "Sweet potatoes" 32 0
"1021001109" 1 "Banana food" 12 0
"1021001109" 1 "Cassava" 2 0
"1021001109" 1 "Maize" .5 0
"1021001109" 2 "Yam" 10 6
"1021001109" 2 "Sugarcane" 120 0
"1021001109" 3 "" . .
"1021001304" 1 "Banana food" 4 0
"1021001304" 1 "Beans" 4 0
"1021001304" 1 "Beans" 10 0
"1021001304" 1 "Cassava" 5 0
"1021001304" 1 "Maize" 1 0
"1021001910" 1 "Banana food" 99999 .
"1021002501" 1 "" . .
"1021002610" 1 "Banana food" 10 0
"1021002610" 1 "Coffee all" 99999 .
"1021002610" 1 "Sweet potatoes" 8 3
"1021002610" 1 "Cassava" 99999 .
"1021002610" 1 "Yam" 5 0
"1021002610" 1 "Groundnuts" 1 0
"1021002610" 1 "Maize" 1 0
"1021002610" 21 "Sweet potatoes" 2 0
"1021002611" 1 "Maize" 1 0
"1021002611" 1 "Maize" 2 2
"1021002810" 1 "Beans" .5 0
"1021002810" 1 "Maize" 2 0
"1021003309" 21 "" . .
"1033000301" 1 "Banana food" 60 0
"1033000301" 1 "Maize" 15 0
"1033000302" 1 "Beans" 3 1
"1033000302" 1 "Cassava" 0 .
"1033000302" 1 "Banana food" 30 20
"1033000302" 1 "Beans" 1 0
"1033000302" 1 "Coffee all" 0 .
"1033000302" 1 "Fallow" 99999 .
"1033000303" 1 "Sweet potatoes" 0 .
"1033000303" 1 "Beans" 0 .
"1033000303" 1 "Cassava" 0 .
"1033000303" 1 "Maize" 3 2
"1033000303" 1 "Banana food" 50 15
"1033000303" 2 "" . .
"1033000303" . "Fallow" 99999 .
"1033000304" 1 "Banana food" 40 0
"1033000304" 1 "Coffee all" 0 .
"1033000304" 1 "Banana beer" 30 0
"1033000304" 21 "Sweet potatoes" 0 .
"1033000304" 22 "Maize" 0 .
"1033000304" 22 "Beans" 1 0
"1033000304" 22 "Maize" 20 0
"103300030403" 1 "Banana food" 5 0
"103300030403" 1 "Coffee all" 2 2
"103300030403" 2 "Banana food" 6 0
"103300030403" 21 "Beans" 1 0
"103300030403" 21 "Cassava" 0 .
"103300030403" 21 "Maize" 7.5 7
"1033000305" 1 "" . .
"1033000305" 2 "" . .
"1033000305" 3 "" . .
"1033000305" 21 "" . .
"1033000307" 1 "Banana beer" 30 0
"1033000307" 2 "Banana beer" 10 0
end
[/CODE]
------------------ copy up to and including the previous line ------------------
Listed 100 out of 15403 observations
Use the count() option to list more
I am relatively new to using formulas in Stata and I want to calculate the Simpson's Diversity Index (Simpson in 1949) for each household (see data below) if this is possible?. Any advice is greatly appreciated! The formula for the Simpson's Index is
Where:
- n = number of individuals of each species
- N = total number of individuals of all species
input str14 HHID float Parcel_ID str20 Crop_name double(Quan_harvested Quan_sold)
"1013000204" 21 "" . .
"1021000108" 1 "Banana food" 48 0
"1021000108" 1 "Cassava" 3 0
"1021000113" 1 "Beans" 3 0
"1021000113" 1 "Dodo" 2 0
"1021000113" 1 "Dodo" 10 0
"1021000113" 1 "Maize" 1 0
"1021000113" 1 "Yam" 99999 .
"1021000408" 1 "Banana food" 99999 .
"1021000408" 1 "Beans" 2 0
"1021000408" 1 "Maize" 1 0
"1021000710" 1 "Banana food" 99999 .
"1021000710" 1 "Beans" 3.5 0
"1021000710" 1 "Maize" 60 0
"1021000807" 1 "Coffee all" 7 7
"1021000807" 1 "" . .
"1021000807" 2 "Banana food" 180 80
"1021000807" 2 "Banana food" 30 0
"1021000807" 2 "Banana food" 90 90
"1021000807" 2 "Cassava" 17 17
"102100080803" 1 "Banana food" 20 0
"102100080803" 1 "Coffee all" 0 .
"102100080803" 2 "Beans" 1 0
"102100080803" 2 "Maize" 1 1
"102100080803" 2 "Groundnuts" 2 0
"102100080803" 2 "Maize" 1 1
"102100080803" 21 "Cassava" 2 0
"102100080803" 21 "Maize" 2.5 1
"102100080803" 21 "Sweet potatoes" 1 0
"102100080803" 21 "" . .
"102100110201" 1 "Beans" 1 0
"102100110201" 1 "" . .
"102100110201" 2 "Cocoa" 4 4
"102100110201" 2 "Coffee all" 1 1
"102100110201" 2 "Groundnuts" 3 0
"102100110201" 3 "Groundnuts" 4 2
"102100110201" 3 "Beans" 1 0
"102100110201" 3 "Cassava" 99999 .
"102100110201" 4 "" . .
"1021001109" 1 "Sweet potatoes" 32 0
"1021001109" 1 "Banana food" 12 0
"1021001109" 1 "Cassava" 2 0
"1021001109" 1 "Maize" .5 0
"1021001109" 2 "Yam" 10 6
"1021001109" 2 "Sugarcane" 120 0
"1021001109" 3 "" . .
"1021001304" 1 "Banana food" 4 0
"1021001304" 1 "Beans" 4 0
"1021001304" 1 "Beans" 10 0
"1021001304" 1 "Cassava" 5 0
"1021001304" 1 "Maize" 1 0
"1021001910" 1 "Banana food" 99999 .
"1021002501" 1 "" . .
"1021002610" 1 "Banana food" 10 0
"1021002610" 1 "Coffee all" 99999 .
"1021002610" 1 "Sweet potatoes" 8 3
"1021002610" 1 "Cassava" 99999 .
"1021002610" 1 "Yam" 5 0
"1021002610" 1 "Groundnuts" 1 0
"1021002610" 1 "Maize" 1 0
"1021002610" 21 "Sweet potatoes" 2 0
"1021002611" 1 "Maize" 1 0
"1021002611" 1 "Maize" 2 2
"1021002810" 1 "Beans" .5 0
"1021002810" 1 "Maize" 2 0
"1021003309" 21 "" . .
"1033000301" 1 "Banana food" 60 0
"1033000301" 1 "Maize" 15 0
"1033000302" 1 "Beans" 3 1
"1033000302" 1 "Cassava" 0 .
"1033000302" 1 "Banana food" 30 20
"1033000302" 1 "Beans" 1 0
"1033000302" 1 "Coffee all" 0 .
"1033000302" 1 "Fallow" 99999 .
"1033000303" 1 "Sweet potatoes" 0 .
"1033000303" 1 "Beans" 0 .
"1033000303" 1 "Cassava" 0 .
"1033000303" 1 "Maize" 3 2
"1033000303" 1 "Banana food" 50 15
"1033000303" 2 "" . .
"1033000303" . "Fallow" 99999 .
"1033000304" 1 "Banana food" 40 0
"1033000304" 1 "Coffee all" 0 .
"1033000304" 1 "Banana beer" 30 0
"1033000304" 21 "Sweet potatoes" 0 .
"1033000304" 22 "Maize" 0 .
"1033000304" 22 "Beans" 1 0
"1033000304" 22 "Maize" 20 0
"103300030403" 1 "Banana food" 5 0
"103300030403" 1 "Coffee all" 2 2
"103300030403" 2 "Banana food" 6 0
"103300030403" 21 "Beans" 1 0
"103300030403" 21 "Cassava" 0 .
"103300030403" 21 "Maize" 7.5 7
"1033000305" 1 "" . .
"1033000305" 2 "" . .
"1033000305" 3 "" . .
"1033000305" 21 "" . .
"1033000307" 1 "Banana beer" 30 0
"1033000307" 2 "Banana beer" 10 0
end
[/CODE]
------------------ copy up to and including the previous line ------------------
Listed 100 out of 15403 observations
Use the count() option to list more
Comment