2345联盟安装系统,2345系统安装,2345联盟推广,2345系统下载,2345一键安装,2345联盟官网,2345系统重装,2345联盟注册,2345系统ISO,2345联盟赚钱,2345系统纯净版,2345联盟代理,2345系统安装教程,2345联盟任务,2345系统GHOST,2345联盟提现,2345系统激活,2345联盟作弊,2345系统兼容,2345联盟软件,2345系统优化,2345联盟平台,2345系统64位,2345联盟合作,2345系统安装包,2345联盟返利,2345系统正版,2345联盟推广方法,2345系统U盘安装,2345联盟佣金,2345系统驱动,2345联盟规则,2345系统PE安装,2345联盟账号,2345系统备份,2345联盟体验,2345系统安全,2345联盟教程,2345系统定制,2345联盟审核,2345系统更新,2345联盟收益,2345系统版本,2345联盟玩法,2345系统装机,2345联盟策略,2345系统镜像,2345联盟工具,2345系统硬盘安装,2345联盟评价,2345系统使用,2345联盟常见问题,2345系统修复,2345联盟经验,2345系统启动盘,2345联盟优缺点,2345系统卸载,2345联盟数据,2345系统破解,2345联盟合规,2345系统封装,2345联盟技巧,2345系统设置,2345联盟骗局,2345系统还原,2345联盟真实性,2345系统速度,2345联盟心得,2345系统内存,2345联盟流程,2345系统错误,2345联盟风险,2345系统蓝屏,2345联盟免责,2345系统安装失败,2345联盟客服,2345系统帮助,2345联盟反馈,2345系统推荐,2345联盟口碑,2345系统评测,2345联盟对比,2345系统性能,2345联盟总结,2345系统最新版,2345联盟2026,2345系统安装步骤,2345联盟SEO,2345系统关键词,2345联盟排名,2345系统搜索,2345联盟引流,2345系统优化技巧,2345联盟流量,2345系统装机量,2345联盟转化率,2345系统用户评价,2345联盟成功率,2345系统安装时长,2345联盟收益截图,2345系统兼容性,2345联盟操作,2345系统自动安装,2345联盟心得分享,2345系统静默安装,2345联盟实战,2345系统无人值守,2345联盟经验分享,2345系统快速安装,2345联盟教程大全,2345系统安装问题,2345联盟解决方案 后台管理
📢 欢迎访问系统之家!所有资源均经过安全检测。

Quartiles (or centiles) by group

发布时间:2026-08-29 | 浏览:1
📥 下载地址(文章开头)
电脑助手解决一切电脑问题。
Login or Register Log in with Forums for Discussing Stata You are not logged in. You can browse but not post. Login or Register by clicking 'Login or Register' at the top-right of this page. For more information on Statalist, see the FAQ . Latest Activity Riccardo Valboni Join Date: Jun 2014 Posts: 123 #1 Quartiles (or centiles) by group 12 Jun 2014, 07:36 Dear all, I am trying to do something conceptually fairly simple. I would like to create a group variable which tells me in which quartile an observation falls into according to the value of a variable. I have tried to do that in this way: by group year: xtile quant=x, nq(4) by it didn't work. I have also tried a bunch of similar codes but none seemed to be effective. The problem is that none of the functions computing quantiles accepts the by option.... Can someone suggest something better? Many thanks! Riccardo Last edited by Riccardo Valboni ; 12 Jun 2014, 07:43 . Tags: None Join Date: Jun 2014 Quartiles (or centiles) by group FernandoRios Join Date: Apr 2014 Posts: 2537 #2 12 Jun 2014, 07:45 Hi Riccardo, There are two options, you can either use a loop: * lets assume your year goes from 1990 to 2000 gen quant=. forvalues i=1990/2000 { capture drop xq xtile xq=x if year==`i', nq(4) replace quant=x if year==`i' } The other is to install egenmore (ssc install egenmore), and use the following: egenmore quant=xtile(x), n(4) by(year) I think both are equally efficient, so since you are doing this by year and ID, you should expect it to take a relatively long time to run the commands. Fernando 1 like Comment Post Cancel Join Date: Apr 2014 Nick Cox Join Date: Mar 2014 Posts: 36100 #3 12 Jun 2014, 07:49 Fernando meant Code: egen quant=xtile(x), n(4) by(year) egenmore is the package name only; the package includes a ragbag of more functions for egen. 3 likes Comment Post Cancel Join Date: Mar 2014 FernandoRios Join Date: Apr 2014 Posts: 2537 #4 12 Jun 2014, 08:15 Thanks Nick. Comment Post Cancel Join Date: Apr 2014 Riccardo Valboni Join Date: Jun 2014 Posts: 123 #5 12 Jun 2014, 09:31 Great, it works even with more than one level of by. Comment Post Cancel Join Date: Jun 2014 Otto Ruokolainen Join Date: Jan 2015 Posts: 9 #6 08 Nov 2019, 07:36 Dear all, My aim is to generate quintiles of a continuous variable (alcohol use/g; variable name: alc) by sex (variable: sex). The range in alc is [0, 1700]. Are there any other ways of doing this very simple task other than suggested by Nick and Fernando above? I am finding it pretty hard to follow Fernando´s suggestion applied to my variables (since I am pretty new to Stata), and I am using Stata at our institute where downloading packages online is either very hard or not allowed. I am using StataSE 16.0. Any advice would be appreciated. Thank you! Comment Post Cancel Join Date: Jan 2015 Nick Cox Join Date: Mar 2014 Posts: 36100 #7 08 Nov 2019, 09:41 It’s not clear whether you want quintile values or the bins they delimit. Either way the trick is to just to repeat say xtile or pctile or the needed command for each distinct value of sex . Comment Post Cancel Join Date: Mar 2014
📥 下载地址(文章中间)
电脑助手解决一切电脑问题。
Nick Cox Join Date: Mar 2014 Posts: 36100 #8 08 Nov 2019, 11:27 Here's a dopey example with quintile bins done separately by distinct values of foreign for mpg in the auto dataset. Code: sysuse auto, clear (1978 Automobile Data) . xtile qmpg1=mpg if foreign==1, nq(5) . xtile qmpg0=mpg if foreign==0, nq(5) . gen qmpg = max(qmpg0, qmpg1) . . tab qmpg foreign | Car type qmpg | Domestic Foreign | Total -----------+----------------------+---------- 1 | 13 5 | 18 2 | 9 5 | 14 3 | 11 5 | 16 4 | 11 3 | 14 5 | 8 4 | 12 -----------+----------------------+---------- Total | 52 22 | 74 . This is the same method as that of @Fernardo Rios in #2, except that there's a typo in his main code segment (and manifestly, he's using 4 bins, not 5). Code: gen quant=. forvalues i=1990/2000 { capture drop xq xtile xq=x if year==`i', nq(4) replace quant=xq if year==`i' } Last edited by Nick Cox ; 08 Nov 2019, 11:36 . Comment Post Cancel Join Date: Mar 2014 Otto Ruokolainen Join Date: Jan 2015 Posts: 9 #9 14 Nov 2019, 04:00 Thank you very much Nick! This worked well for men (sex==1): Code: xtile qalc_1=alc if sex==1, nq(5) xtile qalc_2=alc if sex==2, nq(5) gen qalc = max(qalc_1, qalc_2) However, for women (sex==2) there was zero observations in the second quintile whereas 1,908 (48 % of all for women) observations in the first quintile (see below). I suspect this might be due to the skewness of the original alcohol variable. Code: tab qalc sex alc sex Total 1 2 1 797 1,908 2,705 2 579 0 579 3 695 566 1,261 4 673 767 1,440 5 686 759 1,445 Total 3,430 4,000 7,430 Comment Post Cancel Join Date: Jan 2015 Nick Cox Join Date: Mar 2014 Posts: 36100 #10 14 Nov 2019, 04:22 #9 Those quintile bins look fairly useless in practice. If you need to categorise at all, I would use the values of your variable directly. More discussion at https://www.stata-journal.com/articl...article=dm0095 https://www.stata-journal.com/articl...article=pr0054 Comment Post Cancel Join Date: Mar 2014 Shivam agrawal Join Date: Dec 2019 Posts: 1 #11 04 Dec 2019, 18:43 Nick, when I run egen quant=xtile(x), n(4) by(year) it says tile not found. I am running Stata 14.2 SE! I downloaded egenmore again but its still says unknown function xtile(). I even tried running xtile interd_quartile = interd, n(4) by (career_year) but it lead to the error: option by not allowed Last edited by Shivam agrawal ; 04 Dec 2019, 18:54 . Comment Post Cancel Join Date: Dec 2019 Nick Cox Join Date: Mar 2014 Posts: 36100 #12 05 Dec 2019, 02:54 #11 Installing egenmore from SSC will have precisely no consequences for xtile . It will not mean that xtile now supports a by() option. So your last problem report is not at all surprising. But you say that you downloaded egenmore "again". From your post I can only guess that you put the files in the wrong place. A correct installation will mean that Stata can see a file _gxtile.ado so that asking which will show you something like this: Code: . which _gxtile.ado c:\ado\plus\_\_gxtile.ado *! _gxtile version 1.2 UK 08 Mai 2006 It doesn't matter if your location is different: for example, you may not be using Windows, or your set-up may vary otherwise. What does matter is that Stata can find that program file to use it. What happens sometimes is that people install files with their browser and put them in the wrong place. Or something dopey happens, such as the files acquire an irrelevant extension .html . Note that https://ideas.repec.org/c/boc/bocode/s386401.html explicitly advises Note: This module may be installed from within Stata by typing " ssc install egenmore ". Windows users should not attempt to download these files with a web browser. Here is a self-contained example you can run which should work: Code: . sysuse auto, clear (1978 Automobile Data) . ssc install egenmore, replace . egen wanted = xtile(mpg), n(2) by(foreign) . tab wanted foreign | Car type wanted | Domestic Foreign | Total -----------+----------------------+---------- 1 | 30 11 | 41 2 | 22 11 | 33 -----------+----------------------+---------- Total | 52 22 | 74 Here is the code all in one for convenience: Code: sysuse auto, clear ssc install egenmore, replace egen wanted = xtile(mpg), n(2) by(foreign) tab wanted foreign 1 like Comment Post Cancel Join Date: Mar 2014 Otto Ruokolainen Join Date: Jan 2015 Posts: 9 #13 10 Feb 2022, 01:42 Dear all, I have a fairly simple task: I need to generate a new variable based on tertiles of the variable in interest, taking into account the classes of two different variables. In my case, I need to generate education tertiles (based on years of schooling) taking into account both sex and the year of birth. I have done this taking into account only year of birth as follows: Code: egen education_tertiles =xtile(education_years), n(3) by(year_of_birth) My question is, how to add gender on the by-option? Many thanks for any tips! Best regards, Otto Comment Post Cancel Join Date: Jan 2015 Nick Cox Join Date: Mar 2014 Posts: 36100 #14 10 Feb 2022, 01:46 Code: by(year_of_birth gender) Comment Post Cancel Join Date: Mar 2014 Otto Ruokolainen Join Date: Jan 2015 Posts: 9 #15 10 Feb 2022, 02:19 Dear Nick, Thanks for a prompt answer! My intuition does not always match to that of Stata's (I was trying with commas between the variables, still learning...). A follow-up: when generating the new variable, I should assing ties of the values to means. In SPSS, this is done by default (see here ) : "First, the observations are ordered and given unique, sequential ranks. Then, tied observations have their assigned ranks averaged together." Could this be done in Stata? Best, Otto Comment Post Cancel Join Date: Jan 2015 © Copyright StataCorp LLC Terms of use Privacy Help Contact Us © Copyright StataCorp LLC Terms of use Privacy Help Contact Us © Copyright StataCorp LLC
📥 下载地址(文章结尾)
电脑助手解决一切电脑问题。