Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Multiple kdensity graphs


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Multiple kdensity graphs
Date   Sat, 29 Nov 2003 14:01:18 -0000

I've an -mdensity- wrapper which I'll send privately
to Joao Pedro, as it may help. It's not really
in a fit state to make public.

Nick
n.j.cox@durham.ac.uk

Joao Pedro W. de Azevedo
>
> I've been using the routine below for quite sometime to
> generate multiple
> Kdensity graphs. I've been trying to improve it in the last
> few days, but
> I'm having some trouble with my program skills. I would
> sincerely appreciate
> suggestions.
>
> The two main things that I would like to do are:
>
> 	1) use tempvar
> 	2) automaticaly generate a list to the tempvar
>
> This is an example of this routine, using the stata auto, dataset:
>
>
>
>
> use auto, clear
>
> local cat " foreign"
>
> local var2 " mpg"
>
> local kdensity_settings "epanechnikov nogr"
>
> local scatter_settings "connect(l l)  clwidth(.5 .5 ) msize(.5 .5 )
> legend(textfirst cols(2))  ytitle("Kernel Density")"
>
>
>
>
> 	quietly tabulate `cat', matrow(valnum)
>
> 	local nrows = rowsof(valnum)
>    	local first = valnum[1,1]
> 	local second = valnum[2,1]
> 	local number "`second'"
> 	local i = 3
> 	while `i' <= `nrows' {
> 		local temp = valnum[`i',1]
> 		local number "`number' `temp'"
> 		local i = `i' + 1
> 	}
> 	di "`number'"
> 	local instlist : label `cat' `first'
> 	foreach c in `number' {
> 		local tmp : label `cat' `c'
> 		local instlist "`instlist' `tmp'"
> 	}
> 	di "`instlist'"
>
>
>
>
>
> foreach var in `var2' {
> 	kdensity  `var' if `cat'==valnum[1,1] , `kdensity_settings'
> g(x`var'1 `var'1)
> 	local varlist  "`var'1" /*this was an attempt to
> generate a list of
> the variables generate by kdensity */
>
> 	di `varlist'
>
> 	local s1 : word 1 of `instlist'
> 	label var `var'1 "Density - `s1'"
>
> 		foreach num of numlist 2 {
> 				kdensity  `var' if
> `cat'==valnum[`num',1] ,
> `kdensity_settings' g(`var'`num') at(x`var'1)
> 				local s`num' : word `num' of
> `instlist'
> 				local varlist  "`varlist'
> `var'`num'" /*this
> is part of the attempt to generate a list of the
> variables generate by kdensity */
> 				label var `var'`num' "Density
> - `s`num''"
> 		}
>
> 	di `varlist' /* idealy I would like to use the list
> `varlist' on my
> scatter plot. The probem is that the list that 	I'm
> generating is only
> picking up the first value of the new variable, and the its name. */
>
> 	scatter `var'1 `var'2 x`var'1, `scatter_settings'
>
> 	drop `var'1- `var'2
> }
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index