这需要调查它是如何发生的以及数据是否可以信任。但就Stata技术而言,首先decode
,然后encode
再。示范:
. set obs 3
obs was 0, now 3
. gen numid = _n
. label define numid 1 "AL" 2 "AL" 3 "AL"
. label values numid numid
. list
+-------+
| numid |
|-------|
1. | AL |
2. | AL |
3. | AL |
+-------+
. decode numid, gen(strid)
. list
+---------------+
| numid strid |
|---------------|
1. | AL AL |
2. | AL AL |
3. | AL AL |
+---------------+
. encode strid, gen(newnumid)
. list
+--------------------------+
| numid strid newnumid |
|--------------------------|
1. | AL AL AL |
2. | AL AL AL |
3. | AL AL AL |
+--------------------------+
. list, nolabels
+--------------------------+
| numid strid newnumid |
|--------------------------|
1. | 1 AL 1 |
2. | 2 AL 1 |
3. | 3 AL 1 |
+--------------------------+