Emulation of a target trial using electronic health records and a nested case-control design