Create an id number variable

Not all datasets have an id number variable (for example, if you have performed an anonymous survey, there might not have been a need to mark the questionnaires with any id number). This is easily fixed in Stata.

gen varname = _n

For example:

gen id = _n
Note
Stata will assign numbers in the order that the dataset is sorted, so make sure that you have it sorted in the way you like first.
More information
help generate
help sort