Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: program to calculate specific percentiles


From   "Rodrigo A. Alfaro" <[email protected]>
To   <[email protected]>
Subject   st: Re: program to calculate specific percentiles
Date   Wed, 19 Jul 2006 11:08:00 -0400

Dirk,

(1) Use `rank', `nomiss' and `count' instead of rank, nomiss and count
(2) Define `1' using -tokenize `varlist'.

R.




----- Original Message ----- 
From: Dirk Nachbar
To: statalist
Sent: Wednesday, July 19, 2006 10:43 AM
Subject: st: program to calculate specific percentiles


All
here is a program to calculate specific percentiles. unfortunately it 
reports a syntax error and I don't know why.
capture program drop perc
program define perc
    version 8.2
    syntax varlist [if] [in], [by(name)] groups(int 10) gen(name)
    marksample touse
    qui count if `touse'
    if r(N) ==0 {
            error 2000
            }
    if `groups'>100 | `groups'<1     {
            di as error "there must be between 1 and 100 groups"
            exit 198
            }

qui    {
    tempvar rank nomiss count
    if `by' != "" {
            bysort `by': egen rank=rank(`1')
            bysort `by': gen nomiss=(`1' != .)
            bysort `by': egen count=sum(nomiss)
            bysort `by': gen `gen'=rank/count*`groups'
            }
    else {
            egen rank=rank(`1')
            gen nomiss=(`1' != .)
            egen count=sum(nomiss)
            gen `gen'=rank/count*`groups'
            }
    }
    di "the variable " `gen' " was created"
end
Dirk Nachbar
Assistant Economist
Pensim2
Department for Work and Pensions
Level 4, The Adelphi
1-11 John Adam St
WC2N 6HT London
020 796 28531 
********************************************************************** This 
document is strictly confidential and is intended only for use by the 
addressee. If you are not the intended recipient, any disclosure, copying, 
distribution or other action taken in reliance of the information contained 
in this e-mail is strictly prohibited. Any views expressed by the sender of 
this message are not necessarily those of the Department for Work and 
Pensions. If you have received this transmission in error, please use the 
reply function to tell us and then permanently delete what you have 
received. Please note: Incoming and outgoing e-mail messages are routinely 
monitored for compliance with our policy on the use of electronic 
communications. 
**********************************************************************
The original of this email was scanned for viruses by Government Secure 
Intranet (GSi) virus scanning service supplied exclusively by Cable & 
Wireless in partnership with MessageLabs.
On leaving the GSI this email was certified virus free.
The MessageLabs Anti Virus Service is the first managed service to achieve 
the CSIA Claims Tested Mark (CCTM Certificate Number 2006/04/0007), the UK 
Government quality mark initiative for information security products and 
services. For more information about this please visit www.cctmark.gov.uk 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index