I took a year to do research between 3rd and 4th year, but know many people who did it between 2nd and 3rd year instead. There are pros and cons to each option.
MS2-MS3: If you choose to go this route, I would definitely recommend taking Step 1 at the end of MS2 rather than waiting until you get close to starting MS3. The information will be fresh in your mind and you'll likely do better. My friends who did this seemed to adjust to MS3 fairly easily, and you'll be reading so much about your patients and studying for your shelf exams that I don't really feel like having that extra year in between is too much of a disadvantage. Also, by the time you're applying for residency, more time will have passed since you did your research and so, more papers will likely have been submitted/published as compared to doing it betwwen MS3 and MS4. Having done research between MS3 and MS4, I'm now scrambling to get my paper submitted ASAP so that I can list it on my application for this upcoming cycle. If I had been sure about what field I wanted to go in to before doing my 3rd year rotations, this is probably the route that I would have chosen.
MS3-MS4: Having done some of your 3rd year rotations, you will be better able to select a project/mentor that will be related to your eventual specialty. While most residency programs value research in any field, having a year's worth of face time with a prominent faculty member in your field of interest can be invaluable in opening doors come application time. A research year between MS3 and MS4 is also a good time to get Step 2 out of the way. You will likely have more time to study for it (and therefore get a higher score), and then you won't have to worry about it in between doing sub-is, preparing your application, scheduling interviews, etc. The trade-off, as I mentioned before, is that you'll have less time to get things submitted/published so there may be fewer lines on your resume.