Dear Statalist forum,
I have a dataset with different European countries and NUTS regions within those countries, as well as spatial data for the geographical location of those NUTS regions. For these regions, I have a variable about their average satisfaction with democracy (demosat).
Here is an example of my data:
I want to create a new variable that contains the difference of demosat of each individual region within a country to its national weighted mean of demosat.
The national mean should be calculated uniquely for each row by averaging the regional demosat values weighted by each individual region's geographical distance within a country to the observation, so that closer regions have more influence on their uniquely computed weighted demosat mean. So that, in the end, each row (region) has its own uniquely weighted demosat mean assigned to it that depends on the geographical distance of the other regions within a country to it.
How can I tell Stata to weigh the regional demosat values uniquely for each observation (region) depending on the other regions’ geographical distance to them within a country? Any help would be greatly appreciated.
Best,
Florian
I have a dataset with different European countries and NUTS regions within those countries, as well as spatial data for the geographical location of those NUTS regions. For these regions, I have a variable about their average satisfaction with democracy (demosat).
Here is an example of my data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str24 country str5 nuts_id float(latitude longitude demosat) "Austria" "AT11" 47.2361 16.2874 3.5 "Austria" "AT12" 48.2589 15.7601 3.608511 "Austria" "AT13" 48.2028 16.3932 3.718182 "Austria" "AT21" 46.7161 14.4629 3.352941 "Austria" "AT22" 47.1818 15.5247 3.105769 "Austria" "AT31" 48.143 13.9503 3.3439155 "Austria" "AT32" 47.2823 13.0002 3.6267605 "Austria" "AT33" 47.1809 10.7635 3.564516 "Austria" "AT34" 47.2366 9.8851 3.6756756 "Belgium" "BE1" 50.8401 4.3569 3.3281004 "Belgium" "BE2" 51.1013 4.9852 3.25513 "Belgium" "BE3" 50.4595 4.8252 3.309789 "Bulgaria" "BG31" 43.4201 23.8763 1.9232876 "Bulgaria" "BG32" 43.2223 25.593 2.101523 "Bulgaria" "BG33" 43.3648 27.3512 1.855372 "Bulgaria" "BG34" 42.4799 26.5534 1.969697 "Bulgaria" "BG41" 42.3235 23.3357 2.229202 "Bulgaria" "BG42" 41.7421 25.1669 2.0144033 "Switzerland" "CH01" 46.1381 7.2169 3.5094066 "Switzerland" "CH02" 46.9075 7.4335 3.6487935 end
The national mean should be calculated uniquely for each row by averaging the regional demosat values weighted by each individual region's geographical distance within a country to the observation, so that closer regions have more influence on their uniquely computed weighted demosat mean. So that, in the end, each row (region) has its own uniquely weighted demosat mean assigned to it that depends on the geographical distance of the other regions within a country to it.
How can I tell Stata to weigh the regional demosat values uniquely for each observation (region) depending on the other regions’ geographical distance to them within a country? Any help would be greatly appreciated.
Best,
Florian
Comment