楼主: dayayayl
10279 7

[数据管理求助] 求助:stata如何分组求众数 [推广有奖]

  • 0关注
  • 1粉丝

已卖:2份资源

本科生

55%

还不是VIP/贵宾

-

威望
0
论坛币
227 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
4621 点
帖子
54
精华
0
在线时间
128 小时
注册时间
2011-3-8
最后登录
2020-2-18

楼主
dayayayl 在职认证  发表于 2014-3-16 16:10:17 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
现在有3000家公司月度的S&P评级数据,需要按照公司分别求出一年内评级的众数。数据范例如下:
公司代码 评级 月度
002312 BB 31jan1992
002312 BB 29feb1992
002312 BB 31mar1992
002312 BB 30apr1992
002312 BB 31may1992
002312 BB 30jun1992
002312 BB 31jul1992
002312 BB 31aug1992
002312 BB 30sep1992
002312 BB 31oct1992
002312 BB 30nov1992
002312 BB 31dec1992
002316 A+ 31jan1992
002316 A+ 29feb1992
002316 A+ 31mar1992
002316 A 30apr1992
002316 A 31may1992
002316 A 30jun1992
002316 A 31jul1992
002316 A 31aug1992
002316 A 30sep1992
002316 A 31oct1992
002316 A 30nov1992
002316 A 31dec1992
002322 BB- 31jan1992
002322 BB- 29feb1992
002322 BB- 31mar1992
002322 BB- 30apr1992
002322 BB- 31may1992
002322 BB- 30jun1992
002322 BB- 31jul1992
002322 BB- 31aug1992
002322 BB- 30sep1992
002322 BB- 31oct1992
002322 BB- 30nov1992
002322 BB- 31dec1992
大多数公司都有12个月的数据,也有公司不够12个月,希望能够按照公司名字划分子样本,然后求子样本内的众数,和公司名字一起存成一列。求指点stata代码如何实现。在线等,多谢!!!

二维码

扫码加我 拉你入群

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

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

关键词:Stata tata 如何实现 Mar Dec 如何

沙发
jjjj6666 发表于 2014-3-16 20:50:18
suppose the vars are:
company level date

then do:

gen year=year(date(date,"DMY"))
egen mode=mode(level), by(company year)

藤椅
dayayayl 在职认证  发表于 2014-3-31 11:45:40
jjjj6666 发表于 2014-3-16 20:50
suppose the vars are:
company level date
多谢多谢!很好用!

板凳
S.h.Y 学生认证  发表于 2014-3-31 13:30:50
什么是众数。。。

报纸
jjjj6666 发表于 2014-4-1 04:24:01
众数=mode

地板
手谕7 发表于 2020-4-2 14:11:59
这个命令遇到一组出现相同数量的几个众数时输出不了众数

7
jg_joy16 发表于 2020-9-7 22:35:25
手谕7 发表于 2020-4-2 14:11
这个命令遇到一组出现相同数量的几个众数时输出不了众数
碰到一样的问题,这时候系统会输出 "." 你怎么处理的?

8
懂了DL 学生认证  发表于 2023-2-2 18:42:05
jg_joy16 发表于 2020-9-7 22:35
碰到一样的问题,这时候系统会输出 "." 你怎么处理的?
help egen 往下拉 添加option就行   


mode(varname) [, minmode maxmode nummode(integer) missing]                                                                                                     (allows by varlist:)  
            produces the mode (within varlist) for varname, which may be numeric or string.  The mode is the value occurring most frequently.  If two or more modes exist or if varname
            contains all missing values, the mode produced will be a missing value.  To avoid this, the minmode, maxmode, or nummode() option may be used to specify choices for selecting
            among the multiple modes, and the missing option will treat missing values as categories.  minmode returns the lowest value, and maxmode returns the highest value.  nummode(#)
            will return the #th mode, counting from the lowest up.  nummode() may not be combined with by.  Missing values are excluded from determination of the mode unless missing is
            specified.  Even so, the value of the mode is recorded for observations for which the values of varname are missing unless they are explicitly excluded, that is, by
            if varname < . or if varname != "".

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-30 13:54