I'm looking into satisfaction with GP practices in England and I intend to use deprivation scores for the areas the practices are located in as one of the control variables. I’ve taken the data from the English Indices of Deprivation which are given for Lower layer Super Output Area (LSOA). These contain between 1,000 and 3,000 people, but as the mean number of patients per practice in the dataset is 7,068 patients I thought a more appropriate level for the control variable would be the Middle layer Super Output Area (MSOA) as each of those contain between 5,000 and 15,000 people.
I have the practice code, LSOA code, MSOA code, and deprivation score for LSOAs (please see a sample of the list below). I would now need to calculate the average deprivation score for each MSOA, from several LSOAs each MSOA contains, and then assign this score to each practice in that particular MSOA. And so on for 7,500 observations.
+------------------------------------------------------+
| p_code lsoa msoa dep_mu~l dep_mu~m |
|------------------------------------------------------|
1. | E83012 E01000292 E02000024 10.2398 . |
2. | E83017 E01000248 E02000024 10.16927 . |
3. | E83036 E01000293 E02000024 6.973502 . |
4. | E83042 E01000293 E02000024 6.973502 . |
5. | E83018 E01000129 E02000047 34.26831 . |
|------------------------------------------------------|
6. | E83028 E01000127 E02000047 23.70964 . |
7. | E83032 E01000125 E02000047 36.41887 . |
8. | E83658 E01000129 E02000047 34.26831 . |
+------------------------------------------------------+
From what I’ve read so far, I believe would need to use foreach for this. I’m having trouble writing the command to execute what I described above. Would anybody be able to help with a suggestion please?
I have the practice code, LSOA code, MSOA code, and deprivation score for LSOAs (please see a sample of the list below). I would now need to calculate the average deprivation score for each MSOA, from several LSOAs each MSOA contains, and then assign this score to each practice in that particular MSOA. And so on for 7,500 observations.
+------------------------------------------------------+
| p_code lsoa msoa dep_mu~l dep_mu~m |
|------------------------------------------------------|
1. | E83012 E01000292 E02000024 10.2398 . |
2. | E83017 E01000248 E02000024 10.16927 . |
3. | E83036 E01000293 E02000024 6.973502 . |
4. | E83042 E01000293 E02000024 6.973502 . |
5. | E83018 E01000129 E02000047 34.26831 . |
|------------------------------------------------------|
6. | E83028 E01000127 E02000047 23.70964 . |
7. | E83032 E01000125 E02000047 36.41887 . |
8. | E83658 E01000129 E02000047 34.26831 . |
+------------------------------------------------------+
From what I’ve read so far, I believe would need to use foreach for this. I’m having trouble writing the command to execute what I described above. Would anybody be able to help with a suggestion please?
Comment