zoukankan      html  css  js  c++  java
  • CAR值计算中的转置问题

    在car计算中,我们得到的结果常常是 long 纵向排列的,有时我们也想横向排列一下,也是可以的,在 STATA中使用 reshape 就能够办到。

    clear all
    set more off
    
    *----- example data -----
    
    input ///
    firm    str7 month_year    sales    str3 competitor   str3 competitor_location  str3 competitor_branch_1       str3 competitor_branch_2
      1       "1_2014"    25          "XYZ"            "US"                     "EEE"                      "RRR"
      1       "2_2014"    21          "XYZ"            "US"                    "FFF"
      1       "2_2014"    21          "ABC"            "UK"                     "GGG"
      21     "1_2009"    11          "LKS"           "UK"                      "AAA"
      21     "1_2009"    11          "AIS"            "UK"                      "BBB"
      21     "1_2009"    11          "AJS"            "US"                      "CCC"
      21     "2_2009"    12          "LKS"            "UK"                      "AAA"
    end
    
    encode competitor, gen(comp)
    encode competitor_location, gen(comploc)
    encode competitor_branch_1, gen(compbr1)
    encode competitor_branch_1, gen(compbr2)
    
    gen date = ym( real(substr(month_year,3,.)), real(substr(month_year,1,1)) )
    format date %tm
    
    drop competitor* month*
    
    list
    *----- what you want ?? -----
    
    bysort firm: gen j = _n // this sorting is not unique
    
    reshape wide date sales comp comploc compbr1 compbr2, i(firm) j(j)
    

      

    use "D:
    esults-0422want01_zhuban_03day.dta", clear
    
    *如果你不想显示那么多变量的话,可以提前 drop掉 不想见到的变量.
    
    bysort firm: gen j = _n 
    
    reshape wide date ret  mktret ar evtday, i(firm) j(j)
    

      

  • 相关阅读:
    service
    控制器
    创建私有仓库
    golang xorm MSSQL where查询案例
    golang xorm reverse 自动生成数据库实体文件
    github 获取repo 发布的版本号
    window postgresql 10.4安装
    postgresql 10 数据类型 (完整版)
    postgresql 10 分页
    postgresql 10 ltree 使用说明
  • 原文地址:https://www.cnblogs.com/jungsee/p/8906686.html
Copyright © 2011-2022 走看看