Code for MIDAS