In management research, we usually need to create a variable that measures the experience of firms. Firms accumulate experience as they make acquisitions or invest in companies in certain countries. Sometimes this experience has an effect in future decisions, so we calculate variables that measure the number of times a firm has made an acquisition or has invested in a certain industry or country. In STATA, this can be done using the command –bysort– and –gen– (i.e. –generate-) or –egen-. In this post I will calculate an experience variable using a fictitious dataset.