Statalist The Stata Listserver


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

st: Problem with a ado file


From   "Nuno Soares" <[email protected]>
To   <[email protected]>
Subject   st: Problem with a ado file
Date   Sat, 11 Mar 2006 09:35:31 -0000

Hi everyone,

I'm new at using the STATA programming capabilities and I'm having a problem
with a function I'm trying to implement. The objective is to create a
variable that is able to capture the year specific quintiles of a given
variable into a new variable. Ex. Imagine we have a sample with the income
of the subjects and the year it was surveyed. What I need is to get the
quintile each individual belongs to according to his income, for each year,
for all the years. The xtile command only allows to generate the desired
classification for a each year at a time (and I have 20 years, and i need to
do this to several variables, for several breakpoints).
The ado file I've written is the following:
program qtex
	version 9.0
	args inputvar years outputvar start_year end_year qtiles
	quietly gen `outputvar' =.
	while `start_year'<=`end_year' {
		quietly gen xtile `_tempqt' = `inputvar' if `years' ==
`start_year', nquantiles(`qtiles')
		quietly replace `outputvar' == `_tempqt' if `_tempqt' ~=.
		quietly drop `_tempqt'
		local start_year = `start_year' + 1
		}
end
The inputvar is the variable that is intended to be used for the
classification; years is the variable which holds the year each observation
belongs to; outputvar is the variable that will hold the classification for
each observation; start_year and end_year the start and end periods that
will be used as criteria for classification; qtiles the number of quantiles
to be created.
The message STATA returns is: 
invalid syntax
r(197);

Can anyone help me with this?

Regards,

Nuno

*
*   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