I would like to create a new variable that is an average (weekly) of the "stringency" (example of dataset in the table below) values of a country´s region excluding the country being measured . Although my dataset comprises information on several countries I´m using only a subsample of countries that I called "list_EU_US".
code used to create the group of countries: gen list_EU_US = 1 if inlist(country, "Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus", "Czech Republic", "Denmark", "Estonia") + ///
1 * inlist(country, "Finland", "France", "Germany", "Greece", "Hungary", "Ireland", "Italy") + ///
1 * inlist(country, "Latvia", "Lithuania", "Luxembourg", "Sweden") + ///
1 * inlist(country, "Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "United States")
These are the only countries that I include in my study. I send the example of dataset below. Can you help me with this?
Thank you in advance.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str33 country float(yearweek stringency) "Afghanistan" 3122 0 "Afghanistan" 3123 0 "Afghanistan" 3124 0 "Afghanistan" 3125 0 "Afghanistan" 3126 0 "Afghanistan" 3127 3.57 "Afghanistan" 3128 16.665714 "Afghanistan" 3129 27.78 "Afghanistan" 3130 34.12857 "Afghanistan" 3131 42.99286 "Afghanistan" 3132 64.02 "Afghanistan" 3133 72.351425 "Afghanistan" 3134 81.08286 "Afghanistan" 3135 84.26 "Afghanistan" 3136 84.26 "Afghanistan" 3137 84.26 "Afghanistan" 3138 84.26 "Afghanistan" 3139 84.26 "Afghanistan" 3140 84.26 "Afghanistan" 3141 84.26 "Afghanistan" 3142 83.46571 "Afghanistan" 3143 78.7 "Afghanistan" 3144 78.7 "Afghanistan" 3145 78.7 "Afghanistan" 3146 78.7 "Afghanistan" 3147 78.7 "Afghanistan" 3148 78.7 "Afghanistan" 3149 78.7 "Afghanistan" 3150 78.17142 "Afghanistan" 3151 71.3 "Afghanistan" 3152 63.23143 "Afghanistan" 3153 48.15 "Afghanistan" 3154 21.3 "Afghanistan" 3155 21.3 "Afghanistan" 3156 21.3 "Afghanistan" 3157 22.35714 "Afghanistan" 3158 28.7 "Afghanistan" 3159 25.395714 "Afghanistan" 3160 16.67 "Afghanistan" 3161 16.67 "Afghanistan" 3162 15.611428 "Afghanistan" 3163 9.26 "Afghanistan" 3164 10.054286 "Afghanistan" 3165 12.04 "Afghanistan" 3166 12.04 "Afghanistan" 3167 12.04 "Afghanistan" 3168 12.04 "Afghanistan" 3169 12.04 "Afghanistan" 3170 12.04 "Afghanistan" 3171 12.04 "Africa (total)" 3122 . "Africa (total)" 3123 . "Africa (total)" 3124 . "Africa (total)" 3125 . "Africa (total)" 3126 . "Africa (total)" 3127 . "Africa (total)" 3128 . "Africa (total)" 3129 . "Africa (total)" 3130 . "Africa (total)" 3131 . "Africa (total)" 3132 . "Africa (total)" 3133 . "Africa (total)" 3134 . "Africa (total)" 3135 . "Africa (total)" 3136 . "Africa (total)" 3137 . "Africa (total)" 3138 . "Africa (total)" 3139 . "Africa (total)" 3140 . "Africa (total)" 3141 . "Africa (total)" 3142 . "Africa (total)" 3143 . "Africa (total)" 3144 . "Africa (total)" 3145 . "Africa (total)" 3146 . "Africa (total)" 3147 . "Africa (total)" 3148 . "Africa (total)" 3149 . "Africa (total)" 3150 . "Africa (total)" 3151 . "Africa (total)" 3152 . "Africa (total)" 3153 . "Africa (total)" 3154 . "Africa (total)" 3155 . "Africa (total)" 3156 . "Africa (total)" 3157 . "Africa (total)" 3158 . "Africa (total)" 3159 . "Africa (total)" 3160 . "Africa (total)" 3161 . "Africa (total)" 3162 . "Africa (total)" 3163 . "Africa (total)" 3164 . "Africa (total)" 3165 . "Africa (total)" 3166 . "Africa (total)" 3167 . "Africa (total)" 3168 . "Africa (total)" 3169 . "Africa (total)" 3170 . "Africa (total)" 3171 . end format %tw yearweek
0 Response to Calculate a new variable using values of a country´s region excluding the country being mesured
Post a Comment