Is there fundamental economical reasoning for patriotism? Patriotism is an emotional attachment to a nation which an individual
  recognizes as their homeland.


That is description from Wikipedia and I think it is safe to say that universally all countries in the world trying to create their patriotic agendas. Sometimes it seems natural as it is with deep roots in history, culture. Sometimes it looks very like a ”project”,especially for relatively new countries. 
I am wondering, is there fundamental economical reasoning for that? 
For example, patriotism can lower cost of armies that in one or other history moment helps for country to survive or helps to create more stable economical system and so on. 

Is there any research made in economical reasoning for patriotism? If anyone could give any links to articles or books or just give insights what is economical reasoning for patriotism (if there is one).
I think the purpose of patriotism is to create incentives for actions with positive externalities. 

Your example of joining the army is a good one. The opportunity cost of joining the army is huge. You are risking your life for a relatively meager salary and are not gaining skills in the workplace which you could outside of the army. There is however a very strong positive externality of having a large army with willing participants. 

Patriotism creates an additional incentive for individuals to perform these types of actions which otherwise might not be performed. Actions such as voting, community building, paying taxes, and working in certain industries for lower pay (think ACLU lawyers) are in large part undertaken due to a feeling of community that people within a country feel. This social incentive promotes positive externalities and benefits the society as a whole which is why patriotism is likely such a desirable attribute to be fostered within a country.