Statalist The Stata Listserver

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

st: program to calculate specific percentiles

From   Dirk Nachbar <>
To   statalist <>
Subject   st: program to calculate specific percentiles
Date   19 Jul 2006 15:43:20 +0100


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"


Dirk Nachbar

Assistant Economist


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

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