Hi,
I want to do a "for-value-loop" to create a variable that shows the Gini-Coefficients (made by ginidesc) for the different features of different regional variables. In the following i first tried it for the regional variable with the smallest number of features "REGION" by hand and then with the for value loop, but the order of the values is wrong and i do not know why. Then, i try to do the same thing for the regional variable "CITY" which has more features and it does not work at all. It would be great if someone could help me! Thank you!
ginidesc INCOME, bygroup(REGION)
gen gini_REGION=0.568 if REGION==1
replace gini_REGION=0.579 if REGION==2
replace gini_REGION=0.529 if REGION==3
*create the variable that we want:
gen gini_regiontry = .
*create local with that gives us the number of the provinces
ginidesc allincome, bygroup(REGION) gkmat(ginisregion)
distinct REGION
local region_list = r(ndistinct)
disp(`region_list')
** Loop through each province **
local i = 1
forvalues i = 1(1)`region_list' {
disp(`i')
**Extract the Gini coefficient from the matrix**
local gini_value = ginisregion[`i',2]
disp(`gini_value')
**Assign the Gini coefficient to the corresponding province**
replace gini_regiontry = `gini_value' if REGION == `i'
local ++i
}
local region_list = r(ndistinct)
disp(`region_list')
** Loop through each province **
local i = 1
forvalues i = 1(1)`region_list' {
disp(`i')
**Extract the Gini coefficient from the matrix**
local gini_value = ginisregion[`i',2]
disp(`gini_value')
**Assign the Gini coefficient to the corresponding province**
replace gini_city = `gini_value' if PARROQUIA7 == `i'
local ++i
}
***try for another region: city***
gen gini_city=.
local region_list = r(ndistinct)
disp(`region_list')
** Loop through each province **
local i = 1
forvalues i = 1(1)`region_list' {
disp(`i')
**Extract the Gini coefficient from the matrix**
local gini_value = ginisregion[`i',2]
disp(`gini_value')
**Assign the Gini coefficient to the corresponding province**
replace gini_city = `gini_value' if PARROQUIA7 == `i'
local ++i
}
I want to do a "for-value-loop" to create a variable that shows the Gini-Coefficients (made by ginidesc) for the different features of different regional variables. In the following i first tried it for the regional variable with the smallest number of features "REGION" by hand and then with the for value loop, but the order of the values is wrong and i do not know why. Then, i try to do the same thing for the regional variable "CITY" which has more features and it does not work at all. It would be great if someone could help me! Thank you!
ginidesc INCOME, bygroup(REGION)
gen gini_REGION=0.568 if REGION==1
replace gini_REGION=0.579 if REGION==2
replace gini_REGION=0.529 if REGION==3
*create the variable that we want:
gen gini_regiontry = .
*create local with that gives us the number of the provinces
ginidesc allincome, bygroup(REGION) gkmat(ginisregion)
distinct REGION
local region_list = r(ndistinct)
disp(`region_list')
** Loop through each province **
local i = 1
forvalues i = 1(1)`region_list' {
disp(`i')
**Extract the Gini coefficient from the matrix**
local gini_value = ginisregion[`i',2]
disp(`gini_value')
**Assign the Gini coefficient to the corresponding province**
replace gini_regiontry = `gini_value' if REGION == `i'
local ++i
}
local region_list = r(ndistinct)
disp(`region_list')
** Loop through each province **
local i = 1
forvalues i = 1(1)`region_list' {
disp(`i')
**Extract the Gini coefficient from the matrix**
local gini_value = ginisregion[`i',2]
disp(`gini_value')
**Assign the Gini coefficient to the corresponding province**
replace gini_city = `gini_value' if PARROQUIA7 == `i'
local ++i
}
***try for another region: city***
gen gini_city=.
local region_list = r(ndistinct)
disp(`region_list')
** Loop through each province **
local i = 1
forvalues i = 1(1)`region_list' {
disp(`i')
**Extract the Gini coefficient from the matrix**
local gini_value = ginisregion[`i',2]
disp(`gini_value')
**Assign the Gini coefficient to the corresponding province**
replace gini_city = `gini_value' if PARROQUIA7 == `i'
local ++i
}
Comment