Dear all,
I have tried to create a loop that can replace the Price variables that are missing with the mean of each crop.
For example, I used replace price=mean(crop) if crop ==1
This means that I have to run same command 13 times.
I need a single loop kindly.
Help.
I have tried to create a loop that can replace the Price variables that are missing with the mean of each crop.
For example, I used replace price=mean(crop) if crop ==1
This means that I have to run same command 13 times.
I need a single loop kindly.
Help.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(hhid Crop Quantity Price) 1 2 2500 120 1 3 100 . 1 9 90 . 1 2 2600 100 1 3 150 . 1 9 100 . 2 2 2500 120 2 9 100 . 2 2 400 . 2 888 70 . 3 2 200 . 3 2 300 . 4 2 3000 90 4 9 120 . 4 2 800 . 4 9 80 . 5 2 1500 100 5 2 1500 100 6 2 2500000 90 6 2 3000000 110 7 2 2000 70 7 9 55 . 7 2 1200 120 7 9 20 . 8 2 1300 100 8 2 200 . 8 9 50 . 9 2 500 100 9 2 400 . 10 2 10000 80 10 9 100 . 10 2 4000 100 10 9 60 . 11 2 3000 70 11 2 1500 . 12 2 2000 65 12 2 1200 . 13 1 1000 150 13 2 50 200 13 9 30 . 13 12 5000 300 14 2 5000 80 14 3 200 400 14 2 3000 120 14 9 180 300 15 2 250 80 15 3 5 . 15 1 . . 15 2 100 90 16 2 7000 140 16 2 3000 170 17 2 500 . 17 9 50 . 18 2 25000 80 18 3 300 . 18 2 25000 80 19 2 1500 80 19 2 600 . 20 2 3000 120 20 9 0 . 20 2 300 125 21 2 1000 100 21 2 1200 100 22 2 100 . 22 2 150 . 23 2 80 . 23 9 15 . 23 2 60 . 24 2 500 . 24 9 100 . 24 2 350 . 24 9 120 . 28 2 600 . 28 2 200 . 29 2 1200 80 29 3 120 300 29 2 600 120 30 2 500 70 30 9 15 . 30 2 400 70 30 9 13 . 31 2 100 . 32 9 30 . 32 2 200 . 35 2 200 80 35 9 . . 38 2 1000 . 38 9 60 . 38 2 1000 100 38 9 100 . 39 1 50 100 39 2 200 . 39 2 300 . 39 3 30 . 40 2 800 60 40 2 800 75 41 2 1500 80 41 3 100 300 41 2 800 80 41 9 80 320 end label values Crop dbb01 label def dbb01 1 "Maize", modify label def dbb01 2 "Irish Potatoes", modify label def dbb01 3 "Wheat", modify label def dbb01 9 "Beans", modify label def dbb01 12 "Soya beans", modify label def dbb01 888 "Other specify1", modify