【数据处理】数据转置命令 xpose

2020-07-08  本文已影响0人  冬之心

xpose语法

xpose, clear [options]

    options          Description
    -------------------------------------------------------------------------------
    * clear           必选项。注意,如果原始数据未保存,将会丢失。
      format         使用原始数据的最大数字显示格式
      format(%fmt)   定义转置后数据所有变量的格式
      varname        添加变量 _varname保存原始数据中的变量名
      promote        使用保持数字准确性的最紧凑数据类型
    ---------------------------------------------------------------------------------
    * clear is required.

示例

. webuse xposexmpl, clear
. describe
Contains data from http://www.stata-press.com/data/r15/xposexmpl.dta
  obs:             3                          
 vars:             4                          8 Jan 2016 08:25
 size:            48                          
--------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
--------------------------------------------------------------------------
county          float   %9.0g                 
year1           float   %5.0g                 
year2           float   %6.0g                 
year3           float   %9.0g                 
--------------------------------------------------------------------------
Sorted by: 

. xpose, clear varname format

. describe

Contains data
  obs:             4                          
 vars:             4                          
 size:            80                          
--------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
--------------------------------------------------------------------------
v1              float   %9.0g                 
v2              float   %9.0g                 
v3              float   %9.0g                 
_varname        str8    %9s                   
--------------------------------------------------------------------------
Sorted by: 
     Note: Dataset has changed since last saved.

. list
   -------------------------------
       v1     v2     v3   _varname 
    -------------------------------
  1.   1      2      3     county
  2. 57.2   12.5     18      year1 
  3.  11.3    8.2   14.2      year2 
  4.  19.5   28.9   33.2      year3 
     -------------------------------
上一篇 下一篇

猜你喜欢

热点阅读