Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: using saved values


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: using saved values
Date   Tue, 20 Jan 2009 17:45:14 +0000 (GMT)

--- "Lektzian, David" <[email protected]> wrote:
> using a cross-sectional time series data set organized by country and
> year, I want to do the following:
> By year, generate a variable with the 75th percentile value for
> SqMilesOfLand Then generate another variable =1 if the current value
> for a country of SqMilesOfLand > 75th percentile.

The easiest way to get those percentiles is with -egen-, see -help
egen- and the example below:

*--------- begin example ------------------
sysuse auto, clear
bys rep78 : egen p75 = pctile(mpg) ,p(75)
gen dp75 = mpg > p75
*----------- end example ------------------

> A more general question is that I can't figure out how to call out
> saved values from something like summarize and use them in future
> calculations.

Type -return list- or -ereturn list- to get a list of what is left
behind and how it is called, and than just refer to it using those
names. Sometimes you need to add `' around that name to force Stata to
evaluate the content. The easiest way to find out if that is necesarry
is just not to do that, and if Stata gives you an error add the `'
around the name.

*------------ begin example ----------
sum mpg, detail
return list
gen p75overall = r(p75)

levelsof rep78

gen p75_2 = .
foreach lev in `r(levels)' {
	sum mpg if rep78 == `lev', detail
	replace p75_2 = r(p75) if rep78 == `lev'
}
tab p75 p75_2
*-------------- end example --------------


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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