Hello.
I have some data that, among other variables, contains organisational variables as follows:
ICB Region LTLA
QHM Y63 E06000004
QHM Y63 E06000004
E06000001
QHM Y63 E06000002
QHM Y63 E06000003
QHM Y63 E06000004
QHM Y63 E06000001
E06000003
QHM Y63 E06000002
QHM Y63 E06000001
QHM Y63 E06000002
QHM Y63 E06000003
QHM Y63 E06000004
You can see variable LTLA has missing region and ICB for some observations. However, we know what the region and ICB values should be, because for some observations with these LTLA values the corresponding region and ICB is not missing: for LTLA code E06000001 the corresponding region should be Y63 and region should be QHM: it is only missing for some observations. Where region is missing ICB will always be missing and vice versa. There is never a case where a LTLA code can have more than one region or ICB code, so for LTLA code E06000001 the region and ICB code will always be Y63 and QHM. There are no occasions where LTLA is missing, and there is always at least one occasion where the data is complete i.e. LTLA region and ICB for a given LTLA.
I want to fill in the blanks - the easiest way I know would be create a lookup, there are 7000 LTLA codes and 20 - 30 region and ICB codes and do a merge. However. I was wondering if it would be possible to do this in code - as it would make ii more straightforward when the .do file I am creating is ran again as I wouldn't need to check if the lookup table had been updated - I can fill in the blanks directly from the data.
can anyone advise if there is a relatively simple way to replace the blanks using code?
I have some data that, among other variables, contains organisational variables as follows:
ICB Region LTLA
QHM Y63 E06000004
QHM Y63 E06000004
E06000001
QHM Y63 E06000002
QHM Y63 E06000003
QHM Y63 E06000004
QHM Y63 E06000001
E06000003
QHM Y63 E06000002
QHM Y63 E06000001
QHM Y63 E06000002
QHM Y63 E06000003
QHM Y63 E06000004
You can see variable LTLA has missing region and ICB for some observations. However, we know what the region and ICB values should be, because for some observations with these LTLA values the corresponding region and ICB is not missing: for LTLA code E06000001 the corresponding region should be Y63 and region should be QHM: it is only missing for some observations. Where region is missing ICB will always be missing and vice versa. There is never a case where a LTLA code can have more than one region or ICB code, so for LTLA code E06000001 the region and ICB code will always be Y63 and QHM. There are no occasions where LTLA is missing, and there is always at least one occasion where the data is complete i.e. LTLA region and ICB for a given LTLA.
I want to fill in the blanks - the easiest way I know would be create a lookup, there are 7000 LTLA codes and 20 - 30 region and ICB codes and do a merge. However. I was wondering if it would be possible to do this in code - as it would make ii more straightforward when the .do file I am creating is ran again as I wouldn't need to check if the lookup table had been updated - I can fill in the blanks directly from the data.
can anyone advise if there is a relatively simple way to replace the blanks using code?

Comment