请选择 进入手机版 | 继续访问电脑版

tag 标签: creates经管大学堂:名校名师名课

相关帖子

版块 作者 回复/查看 最后发表
【畅销书系列】Scaling Up Excellence 升级优秀:怎样实现卓越规模化 attach_img 创新与战略管理 wwqqer 2014-12-30 135 24782 olympic 2022-9-21 20:43:48
【金融教材系列】Bayesian Risk Management attach_img 金融学(理论版) wwqqer 2016-1-19 101 10819 etoy 2022-8-27 09:21:52
【经典教材系列】Incomplete Categorical Data Design - [阅读权限 14]attach_img 计量经济学与统计软件 wwqqer 2016-1-24 56 3369 三江鸿 2022-5-16 14:20:47
Googles PageRank and Beyond - The Science of Search Engine Rankings attachment 商学院 koalachen2013 2014-1-28 4 3302 楚天江南客 2018-11-15 13:23:14
PHstat2 version3.07(EXCEL插件) attachment Excel 410234198 2014-3-25 18 15368 lamyohin 2018-1-30 11:33:39
R for Data Science: Visualize, Model, Transform, Tidy, and Import Data (free) attach_img 量化投资 igs816 2016-11-22 112 8139 Henrychen67 2017-11-3 01:41:02
【企业金融家】 The Corporate Financiers attach_img 金融学(理论版) cmwei333 2016-11-21 25 1978 MouJack007 2017-4-13 11:38:57
【在多变的市场累计房地产财富】Building Real Estate Wealth in a Changing Market attach_img 金融学(理论版) cmwei333 2016-10-17 16 2071 kp1 2016-11-7 11:17:53
求moody‘s关于UK WATER的三篇分析报告!!!重金 金融实务版 病雪 2016-7-2 0 543 病雪 2016-7-2 17:58:18
悬赏 求助Pancreatic cancer risk variant in LINC00673 - [!reward_solved!] attachment 求助成功区 刀剑林 2016-5-26 1 1010 mj2012 2016-5-26 17:04:03
[Java文库]Mastering JavaScript Design Patterns attachment JAVA语言开发 NewOccidental 2015-3-27 2 1242 东西方咨询 2016-5-7 20:13:00
悬赏 adv 130中37 关于least cpu usage的 - [!reward_solved!] SAS专版 mandyfervor 2015-11-2 1 1333 johnpark1 2015-11-3 12:37:19
Using a URLConnection using Java JAVA语言开发 Lisrelchen 2015-6-5 0 1430 Lisrelchen 2015-6-5 11:00:02
悬赏 求助Diet creates metabolic niches in the "inmature gut" - [!reward_solved!] attachment 求助成功区 cjhong111 2014-8-15 1 1020 auirzxp 2014-8-16 02:02:09
Rise of CDO creates threats, opportunities for CIOs 数据管理、XBRL、BI、CI kissky 2013-12-9 0 921 kissky 2013-12-9 08:49:39
悬赏 四篇外文文献求助 - [!reward_solved!] attachment 求助成功区 warsky 2013-8-13 1 668 giresse 2013-8-13 11:56:53
【下载】2012美国动作《四十日夜》1280X720/BD-MKV[中文字幕] 休闲灌水 Dream? 2013-5-11 1 2393 haffer 2013-5-13 10:28:53
US creates task force to target unfair trade practices 真实世界经济学(含财经时事) dq19871223 2012-2-29 0 1084 dq19871223 2012-2-29 20:02:29
20111118 Folllow Me 192 global tax landscape 真实世界经济学(含财经时事) whachel1976 2011-11-18 25 3083 okko123 2011-11-23 19:42:17

相关日志

分享 sum() total() pc() rowtotal()
xiongjerry 2015-3-31 11:19
sum() total() pc() rowtotal() 下为stata11 Manual中的例子,从上里来看,sum()和total()两个函数是不同的,其中sum()为按照下标动态累加。而total()是求总和。但应该 注意的是这里是stata's sum() VS egen's total(),如果在egen下使用sum(),作用与total()相同。 Distinguish carefully between Stata’s sum()function and egen’s total()function. Stata’s sum()function creates the running sum, whereas egen’s total() function creates a constant equal to the overall sum. For example: clear set obs 5 gen a=_n gen sum1=sum(a) egen sum2=total(a) list 执行结果如下: . do "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\STD00000000.tmp" . clear . set obs 5 obs was 0, now 5 . gen a=_n . gen sum1=sum(a) . egen sum2=total(a) end of do-file . list +-----------------+ | a sum1 sum2 | |-----------------| 1. | 1 1 15 | 2. | 2 3 15 | 3. | 3 6 15 | 4. | 4 10 15 | 5. | 5 15 15 | +-----------------+ 如果将上述例子稍微修改,将第四行代码中gen改为egen如下: clear set obs 5 gen a=_n egen sum1=sum(a) egen sum2=total(a) list 执行结果如下: . clear . set obs 5 obs was 0, now 5 . gen a=_n . egen sum1=sum(a) . egen sum2=total(a) end of do-file . list +-----------------+ | a sum1 sum2 | |-----------------| 1. | 1 15 15 | 2. | 2 15 15 | 3. | 3 15 15 | 4. | 4 15 15 | 5. | 5 15 15 | +-----------------+ sum()、total()两个命令的应用: 请问如何用stata命令求在下列四组每个公司在各自行业中的销售额比率?如行业1,先求行业内四个公司的销售总额,然后求A1,A2...各自占行业的份额。 公司 Sales 行业 A1 27.72 1 A2 26.37 1 A3 24.79 1 A4 18.69 1 B1 17.48 2 B2 17.04 2 B3 10.87 2 B4 6.68 2 C1 9.06 3 C2 6.8 3 C3 8.85 3 C4 9.43 3 D1 11.48 4 D2 13.96 4 D3 14.19 4 D4 17.93 4 使用total()或者sum()函数就可以完成这个任务,为避免中文无法识别,将行业变量命名为industry 代码如下: by industry ,sort : egen sale_s=total(Sales) gen ratio=Sales/sale_s 当然,stata中还有一个一直的求所占比率的函数pc(),这个也是egen命令的fnc之一。 改进的命令为: by industry, sort: egen ratio=pc(Sales),prop 关于pc() pc( exp ) (allows by varlist ) returens exp (within varlist) scaled to be a percentage of the total, between 0 and 100. The prop option returns exp scaled to be a proption of the total, between 0 and 1. 此为stata11中egen函数下pc()的说明,从内容来看,pc()这一function可以返回变量某一取值占总和的比重,加上prop这一option之后,可将百分数改为0到1之间的小数。而且,此function可与by连用,从而功能更加强大。 关于rowtotal(): generate’s sum()function creates the vertical, running sum of its argument, whereas egen’stotal()function creates a constant equal to the overall sum. egen’s rowtotal()function, however,creates the horizontal sum of its arguments. They all treat missing as zero. However, if the missingoption is specified with total()or rowtotal(), then newvar will contain missing valuesif allvalues of exp or varlist are missing. 从这段话来看,sum()函数做的是纵向合并,total()函数得到的是最终的和,二rowtotal()函数则是横向求和。三种函数都把缺省值视为数值0。 例子: . webuse egenxmpl4,clear . egen hsum=rowtotal(a b c) . generate vsum=sum(hsum) . egen sum=total(hsum) . list +----------------------------------+ | a b c hsum vsum sum | |----------------------------------| 1. | . 2 3 5 5 63 | 2. | 4 . 6 10 15 63 | 3. | 7 8 . 15 30 63 | 4. | 10 11 12 33 63 63 | +----------------------------------+ end of do-file 这个例子生动的展示了sum() total() rowtotal() 之间的区别。
个人分类: stata命令|12 次阅读|0 个评论

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

GMT+8, 2024-3-29 05:40