Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input double hhid int intyear double(dst2012 dst2010 dst2008)
1010140020171 2008 .71 .71 4.124
1010140020171 2010 .71 .71 4.124
1010140020171 2012 .71 .71 4.124
1010140020284 2008 .71 .71 4.124
1010140020284 2010 .71 .71 4.124
end

Hi there,

I working to build a panel dataset and I've run into a bit of trouble figuring out how to create a single distance variable from three separate distance variables based on year. I need a variable that will pull in the correct distance based on the year variable. E.g., in the first observation, I'd like the hhid for 2008 to correspond to a single variable that would pull in the dst2008 first observation, while the next hhid observation would correspond to dst2010. Any help would be greatly appreciated.

Kind regards,