Once, a colleague of mine has told that he used to limit himself to working in the same company for no more than two years. He had a chance to work in the top tech companies. I’m working with the same crowd for years which is not a leading tech company, is more like a startup and has potential. Furthermore, my parents and their parents used to working almost all their lives in one place. But which is better: staying long in one place or changing them often?
What people usually do
Anecdotal evidence suggests that before, people were stuck with one job throughout their working life. But just looking into baby boomers, it is not the case. “Individuals born in the latter years of the baby boom (1957-1964) held an average of 12.3 jobs from age 18 to age 52, according to the U.S. Bureau of Labor Statistics.”  A decade ago, an article in Forbes mentioned this number increased . I could not find the source of the study mentioned in the story.
Averages tell us something but not everything. It is clear that people change jobs, and there is an indication that this happens more often. Unfortunately, it does not say if the change is actually for the better. What is more, this only applies to the U.S., and what about European countries, or China, or Brasil?
Let’s look into the remuneration and check the averages for salary raises. It seems the average annual increase is floating around 3%  at the moment. It means that your salary triples over 38 years. If you started to work at a company immediately after college, say at the age of 22, with the starting salary of $30k; then when you’re 30, it would be $38k, when 40, it would be $51k, then 50 it would be $68k.
The above example does not sound like a lot, and you would probably want to earn $100+ in your thirties, but how then? One way is obviously to start with a bigger salary. If you started with $60k, then when you’re 30, it would be $76k. Another approach is to actually switch jobs. Investopedia  mentions that it used to be the switch could raise your salary by 10-20%, albeit without sources to prove it. But it makes sense because if you want to negotiate with your current employer, you want to have an alternative proposal that will reflect your market position, or you can always bluff. The problem with bluffing is that you might get burned if your current employer disagrees, and you discover that nobody wants to pay that price as well. With the alternative offer, you just go to another job and get paid more regardless.
I am in a tech position - a software engineer. As far as I know, it differs from other engineering disciplines due to the unbounded problem space. For instance, the construction sector is heavily regulated, and many design decisions are already encoded in regulations, i.e. welds, use of metal structures, compliance with fire safety, HVAC, etc. So when you get the skills, you can resell them for a long time until some shifts in regulation. In software, it is not the case as everything often changes as there is no meaningful regulation and vice versa. For instance, if you’re working on a monolith and then want to find a job, you’ll not succeed with companies working with microservices and vice versa.
I do not know of any studies regarding the upskilling of software engineers. Still, from my own experience, I know that small companies tend to reduce the complexity, thus sticking to the same technology stacks. It seems this poses a risk for an employee in the long run due to the shortage and variety of skills she gains. New skills do not get introduced unless there is some experimentation or courses. Otherwise, an employee has to do something after work to ensure she can be more mobile.
It looks like in software you need to move among small companies to gain more skills. Or you could also do courses, but those are not considered professional experience. On the other hand, if you’re in a large company then changing departments might help.
Specializing in one narrow domain could be another approach, but software moves at breakneck speed, and you might quickly become irrelevant. Any mainframe devs here?
According to Investopedia , your salary could increase more than an average if you switched a job. Also, it is pretty normal these days to change careers . My own interpretation of skills acquisition also hints that it is a shorter path to learning more.
Why would you stay then? It might be people, ease of commute, prestige, potential. But then you have to make sure the company moves in the right direction for you to be employable in the future.
-  Number of Jobs Held in a Lifetime https://www.bls.gov/nls/questions-and-answers.htm#anch41 and https://www.bls.gov/news.release/pdf/nlsoy.pdf
-  The Future Of Work: Job Hopping Is the ‘New Normal’ for Millennials https://www.forbes.com/sites/jeannemeister/2012/08/14/the-future-of-work-job-hopping-is-the-new-normal-for-millennials/
-  Salary Secrets: What is Considered a Big Raise? https://www.investopedia.com/articles/personal-finance/090415/salary-secrets-what-considered-big-raise.asp#citation-1
-  U.S. employers plan to hold the line on pay raises in 2020, Willis Towers Watson survey finds https://www.willistowerswatson.com/en-US/News/2019/08/us-employers-plan-to-hold-the-line-on-pay-raises-in-2020