There's another factor to consider: green-handcuffs.
This is the term used when an H1B worker has applied for a green-card, would like to change jobs, but can't, because it would require starting the application process over from the beginning. Obtaining a green card while on an H1B can take 6 years (or as short as a year). I used to work for a company in silicon valley that would hire H1B workers, pay them significantly lower wages (and get away with 'paying market rate' by changing the job description to one where the market was significantly lower than the position he was actually working in), encourage the worker to apply for a green card, then do what it could to stall the process so they could keep the cheap worker longer.
The H1B workers called it green-handcuffs and would leave the minute they got their green card.
I currently know a guy who went to work for a company on a particular project. the project got canned, so he got moved to another position in the company. a position he hates. he'd leave, but he's close to getting his green card approved and doesn't want to start the process all over again.