楼主: 黃河泉
1963 16

[程序分享] 多层表格 [推广有奖]

大师

52%

还不是VIP/贵宾

-

威望
3
论坛币
34526 个
通用积分
55890.0311
学术水平
3538 点
热心指数
3698 点
信用等级
2921 点
经验
308755 点
帖子
14503
精华
12
在线时间
7393 小时
注册时间
2016-7-9
最后登录
2024-4-27

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
下列例子取自 https://www.statalist.org/forums ... tabulation-question。一般表格 ( 3 个变量),可为 tablecol.png
其程序为 (请先 search tablecol 并安装)
  1. // Prepared to illustrate question at:
  2. // https://www.statalist.org/forums/forum/general-stata-discussion/general/1430851-interesting-tabulation-question

  3. // Set workspace.
  4. set more off
  5. clear all
  6. set obs 1000

  7. // Define a shuffle function.
  8. program shuffleit
  9.     set seed 123456
  10.     gen srtr = runiform(0,100)
  11.     sort srtr
  12.     drop srtr
  13. end

  14. // Create fictional planting year data.
  15. gen plantyear = 2010
  16. replace plantyear = 2011 if _n > 750
  17. replace plantyear = 2012 if _n < 250
  18. replace plantyear = 2013 if _n > 475 & _n < 650
  19. replace plantyear = 2014 if _n > 300 & _n < 425

  20. // Shuffle the data.
  21. shuffleit

  22. // Create fictional cultivation data.
  23. gen result = 0
  24. replace result = 1 if _n > 630
  25. replace result = 2 if _n > 870
  26. label define col_heads 0 "Not Grmntd" 1 "Grmntd" 2 "Fruited"
  27. label values result col_heads

  28. // Display a summary of the data with tabulate.
  29. tab plantyear result

  30. // Shuffle the data.
  31. shuffleit

  32. // Add some geographic data.
  33. gen region = 0
  34. replace region = 1 if _n > 600
  35. label define ns 0 "South Fields" 1 "North Fields"
  36. label values region ns

  37. // Display a summary of the data with tablecol (ssc install tablecol)
  38. tablecol plantyear result region, row col
复制代码



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝


table.png (8.75 KB)

table.png

已有 1 人评分经验 论坛币 学术水平 热心指数 收起 理由
葫芦娃大王 + 1 + 1 + 1 + 1 精彩帖子

总评分: 经验 + 1  论坛币 + 1  学术水平 + 1  热心指数 + 1   查看全部评分

本帖被以下文库推荐

沙发
qiangli 发表于 2018-2-21 09:04:59 来自手机 |只看作者 |坛友微信交流群
table也可以实现
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
葫芦娃大王 + 3 + 3 精彩帖子
黃河泉 + 3 + 3 + 3 观点有启发

总评分: 学术水平 + 6  热心指数 + 6  信用等级 + 3   查看全部评分

使用道具

藤椅
黃河泉 在职认证  发表于 2018-2-21 09:32:10 |只看作者 |坛友微信交流群
qiangli 发表于 2018-2-21 09:04
table也可以实现
愿闻其详 (特别是三个变量)。

使用道具

板凳
蓝色 发表于 2018-2-21 09:36:11 |只看作者 |坛友微信交流群
黃河泉 发表于 2018-2-21 09:32
愿闻其详 (特别是三个变量)。
  1. . gen id=1

  2. . table plantyear result region,c(count id)  row col

  3. ------------------------------------------------------------------------------------------------------------
  4.           |                                        region and result                                       
  5.           | ---------------- South Fields ----------------    ---------------- North Fields ----------------
  6. plantyear | Not Grmntd      Grmntd     Fruited       Total    Not Grmntd      Grmntd     Fruited       Total
  7. ----------+-------------------------------------------------------------------------------------------------
  8.      2010 |         73          31          17         121            56          18           8          82
  9.      2011 |         96          38          14         148            61          25          16         102
  10.      2012 |         98          30          19         147            65          18          19         102
  11.      2013 |         65          31          14         110            41          19           4          64
  12.      2014 |         46          16          12          74            29          14           7          50
  13.           |
  14.     Total |        378         146          76         600           252          94          54         400
  15. ------------------------------------------------------------------------------------------------------------
复制代码
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
葫芦娃大王 + 5 + 5 + 5 精彩帖子
黃河泉 + 5 + 5 + 5 精彩帖子

总评分: 学术水平 + 10  热心指数 + 10  信用等级 + 10   查看全部评分

使用道具

报纸
蓝色 发表于 2018-2-21 09:44:59 |只看作者 |坛友微信交流群
黃河泉 发表于 2018-2-21 09:32
愿闻其详 (特别是三个变量)。
4维表格也可以做的
table.png table1.png table4.png
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
黃河泉 + 5 + 5 + 5 精彩帖子

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

使用道具

地板
黃河泉 在职认证  发表于 2018-2-21 10:07:06 |只看作者 |坛友微信交流群
蓝色 发表于 2018-2-21 09:36
谢谢蓝色版主的例子,我从没试过类似作法。
已有 1 人评分经验 论坛币 学术水平 热心指数 收起 理由
葫芦娃大王 + 1 + 1 + 5 + 5 精彩帖子

总评分: 经验 + 1  论坛币 + 1  学术水平 + 5  热心指数 + 5   查看全部评分

使用道具

7
zabbyy 发表于 2018-2-24 08:17:40 |只看作者 |坛友微信交流群
谢谢分享

使用道具

8
zjdxj0405 发表于 2018-2-24 09:09:55 |只看作者 |坛友微信交流群
谢谢黄老师分享!

使用道具

9
想是忘机者2 发表于 2018-2-24 11:11:05 |只看作者 |坛友微信交流群
感谢黄老师分享!

使用道具

10
黃河泉 在职认证  发表于 2018-2-24 11:29:30 |只看作者 |坛友微信交流群
我是抛砖引玉,引出蓝色版主的有趣与有用的建议(虽然我自己不常用此指令,但也学习新的东西)。

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 04:18