Hello,
I’m working with longitudinal data, for which I have quite a few variables matched by country (variable name countryname) and year (variable name year). I’m looking at data between 2014 and 2020 for each country, and need to interpolate the missing observations for my covariates.
The tricky part is that I should not interpolate any missing values for years before the earliest year for which there is data, or after the last year with data for any given country. For example, if there is data for Botswana in 2016, 2018, and 2019, I would only want to interpolate between 2016 and 2019.
The problem is that the range of years that I would need to interpolate between varies country to country. Is there a way to interpolate missing values while indicating that the interpolation needs to be EXCLUSIVELY between whatever the first and last year of observations happen to be for each country? I’m ideally looking for code that would generate one new variable (e.g. covariate_new) with all the interpolated data for all the countries instead of having to go through country by country and merge them later.
I hope this was a clear enough description. Thank you in advance for any advice you might have!
I’m working with longitudinal data, for which I have quite a few variables matched by country (variable name countryname) and year (variable name year). I’m looking at data between 2014 and 2020 for each country, and need to interpolate the missing observations for my covariates.
The tricky part is that I should not interpolate any missing values for years before the earliest year for which there is data, or after the last year with data for any given country. For example, if there is data for Botswana in 2016, 2018, and 2019, I would only want to interpolate between 2016 and 2019.
The problem is that the range of years that I would need to interpolate between varies country to country. Is there a way to interpolate missing values while indicating that the interpolation needs to be EXCLUSIVELY between whatever the first and last year of observations happen to be for each country? I’m ideally looking for code that would generate one new variable (e.g. covariate_new) with all the interpolated data for all the countries instead of having to go through country by country and merge them later.
I hope this was a clear enough description. Thank you in advance for any advice you might have!
Comment