Doctoral stay in foreign university I am a PhD student in my second year, and I am thinking about doing a doctoral stay in some foreign university with a group that works on the same topic as I am. I do know about some interesting research groups where I could do this kind of doctoral activity. However, I am unsure about how does some proceed to pursue this kind of research position. 

Does one directly write to the group presenting yourself and what are you doing (also presenting some of your published work)? Do you have to follow a formal application at the target university? Does it depend on the country/institution?
If you simply want to work with them and don't require either a formal position or funding then you just need to talk to the PI of the research group and deal with visas and such. 

But if you need funding, it is a separate issue that might be handled by the PI (via their grants) or by the university. You might be able to arrange your own grant, of course via some agency. 

If you desire some official position, such as formal matriculation, then that can only be granted by the institution. That will generate an academic record for your stay. Later in your career, the position of Visiting Professor might be open to you, but from the institution.

But you need to talk to the PI in every case. Give them your qualifications and your interests. Treat it like you would any application. Convince them of your suitability and likelihood of success.