Hello!
I have run into an issue where _n does not refer to the observation number.
The commands and results I have seen are listed below:
. gen id = _n
. format id %22.0f
. list id in 16777213 / 16777219
---ob no----+-----id-------+
16777213. | 16777213 |
16777214. | 16777214 |
16777215. | 16777215 |
16777216. | 16777216 |
16777217. | 16777216 |
16777218. | 16777218 |
16777219. | 16777220 |
---------------+---------------+
Is there a particular reason why this would be happening? I have tried other methods too such as the one below but always get similar results.
. gen id = 1
. gen sumid = sum(id)
. format id sumid %22.0f
. list id sumid in 16777213 / 16777219
---ob no----+-id---sumid---+
16777213. | 1 16777213 |
16777214. | 1 16777214 |
16777215. | 1 16777215 |
16777216. | 1 16777216 |
16777217. | 1 16777216 |
16777218. | 1 16777218 |
16777219. | 1 16777220 |
----------------+-----------------+
My ultimate goal would be to generate a variable with a unique id for each of the observations. Would there be any way to work around this?
Thank you for your time and help!
I have run into an issue where _n does not refer to the observation number.
The commands and results I have seen are listed below:
. gen id = _n
. format id %22.0f
. list id in 16777213 / 16777219
---ob no----+-----id-------+
16777213. | 16777213 |
16777214. | 16777214 |
16777215. | 16777215 |
16777216. | 16777216 |
16777217. | 16777216 |
16777218. | 16777218 |
16777219. | 16777220 |
---------------+---------------+
Is there a particular reason why this would be happening? I have tried other methods too such as the one below but always get similar results.
. gen id = 1
. gen sumid = sum(id)
. format id sumid %22.0f
. list id sumid in 16777213 / 16777219
---ob no----+-id---sumid---+
16777213. | 1 16777213 |
16777214. | 1 16777214 |
16777215. | 1 16777215 |
16777216. | 1 16777216 |
16777217. | 1 16777216 |
16777218. | 1 16777218 |
16777219. | 1 16777220 |
----------------+-----------------+
My ultimate goal would be to generate a variable with a unique id for each of the observations. Would there be any way to work around this?
Thank you for your time and help!
Comment