STATA 用变量原有值标签的显示值来代替,删除原有的值标签

. des
//变量provinces对应的值标签s41lab
// Contains data from 1xx.dta
//  Observations:            10                  
//     Variables:             2                  6 Apr 2023 12:14
// --------------------------------------------------------------------------------------------------------------------------------------
// Variable      Storage   Display    Value
//     name         type    format    label      Variable label
// --------------------------------------------------------------------------------------------------------------------------------------
// id              float   %9.0g                 问卷编号
// provinces       float   %24.0g     s41lab     采访地点-省/自治区/直辖市编码
// --------------------------------------------------------------------------------------------------------------------------------------
// Sorted by: id
. label list s41lab
//显示对应的值标签的真实含义
// s41lab:
//            1 上海市
//            2 云南省
//            3 内蒙古自治区
//            4 北京市
//            5 吉林省
//            6 四川省
//            7 天津市
gen ax=provinces
. list
//
//      +--------------------+
//      | id   provin~s   ax |
//      |--------------------|
//   1. |  1     北京市    4 |
//   2. |  3     北京市    4 |
//   3. |  4     北京市    4 |
//   4. |  5     北京市    4 |
//   5. |  8     北京市    4 |
//      |--------------------|
//   6. |  9     北京市    4 |
//   7. | 14     北京市    4 |
//   8. | 16     北京市    4 |
//   9. | 17     北京市    4 |
//  10. | 19     北京市    4 |
//      +--------------------+
gen sheng=string(provinces)
. list

//      +----------------------------+
//      | id   provin~s   ax   sheng |
//      |----------------------------|
//   1. |  1     北京市    4       4 |
//   2. |  3     北京市    4       4 |
//   3. |  4     北京市    4       4 |
//   4. |  5     北京市    4       4 |
//   5. |  8     北京市    4       4 |
//      |----------------------------|
//   6. |  9     北京市    4       4 |
//   7. | 14     北京市    4       4 |
//   8. | 16     北京市    4       4 |
//   9. | 17     北京市    4       4 |
//  10. | 19     北京市    4       4 |
//      +----------------------------+

// ssc install sdecode
//安装sdecode,将provinces用其原有的值标签的值为内容,结果只有具体值,原有的值标签没有了
sdecode provinces ,replace
 . des
//
// Contains data from 1xx.dta
//  Observations:            10                  
//     Variables:             4                  6 Apr 2023 12:14
// --------------------------------------------------------------------------------------------------------------------------------------
// Variable      Storage   Display    Value
//     name         type    format    label      Variable label
// --------------------------------------------------------------------------------------------------------------------------------------
// id              float   %9.0g                 问卷编号
// provinces       str9    %9s                   采访地点-省/自治区/直辖市编码
// ax              float   %9.0g                 
// sheng           str1    %9s                   
// --------------------------------------------------------------------------------------------------------------------------------------
// Sorted by: id
//      Note: Dataset has changed since last saved.

 

posted @ 2023-04-06 12:26  myrj  阅读(539)  评论(0编辑  收藏  举报