Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: RE: Jittering problem


From   Fred Wolfe <[email protected]>
To   [email protected]
Subject   Re: st: RE: Jittering problem
Date   Fri, 20 May 2011 10:15:56 -0500

Thanks, Nick. I hoped there was a simple code alteration that would do the job.

As to your suggestion, I discovered a Version 6 (circa 2000) ado file
I wrote to do this. I think this was before Stata introduced
jittering. It probably could use some updating:

*! jitter.ado adds random noise to variable usually for graphing
purposes 6/11/00
*! syntax varname,Gen(newvar),Percent(real number - default is 2%)
program define jitter
	version 6.0
	syntax varlist(max=1) [if] [in][,Gen(string) Percen(real 2)]
	tokenize `varlist'
	confirm new v `gen'
	marksample touse
	qui su `varlist' if `touse'
	local range = (r(max) - r(min))
	local prop = `percen' / 100
	tempvar random
	qui gen `random' = ((uniform() * 2)-1) * (`prop' * `range')
	qui gen `gen' = `varlist' + `random' if `touse'
	label variable `gen' "`varlist' plus `percen' % random noise"
end

 jitter fatigue, g(jfatigue) p(4)

. des jfatigue

              storage  display     value
variable name   type   format      label      variable label
-----------------------------------------------------------------------------------------------------------------------------
jfatigue        float  %9.0g                  fatigue_scale plus 4 %
random noise

Fred

On Fri, May 20, 2011 at 9:13 AM, Nick Cox <[email protected]> wrote:
> This is more portable than Fred's example if you are not a collaborator of his and thus do not share his data.
>
> sysuse auto, clear
>
> gen m = word(make, 1)
>
> scatter head rep78 if !foreign, jitter(8) ///
> || scatter head rep78 if foreign, jitter(8) scheme(bw)
>
> more
>
> scatter head rep78 if !foreign, jitter(8) mla(m) ///
> || scatter head rep78 if foreign, jitter(8) scheme(bw) mla(m)
>
> The essence of the problem appears to be that using marker labels inhibits jittering. I guess wildly that the way that jittering is implemented rules out -mla()- knowing exactly where to put the marker label, so jittering is ignored.
>
> So, I guess further that you need to pre-jitter yourself by adding random noise. An automated way to do this would use some fraction of the range of each variable multiplied by -runiform()-.
>
> Nick
> [email protected]
>
> Fred Wolfe
>
> When I use this command, the graph will be jittered:
>
> scatter fatig glb_ if ra_sev==0, jitter(8) || scatter fatig glb_ if
> ra_sev >0, jitter(8) scheme(bw).
>
> It will not be jittered when I use this command:
>
>
>  scatter fatig glb_ if ra_sev==0,mfcolor(white) color(black) msize(
> medlarge) mlabel(ptglobak) jitter(8) || scatter fatig glb_ if ra_sev
>>0,mfcolor(black) xline(1.1)  msize(medlarge) msymbol(circle)
> mlabel(ptglobak) jitter(8) scheme(bw).
>
>  I couldn't find any discussion of this problem on the list. Any
> suggestions to make jittering work?
>
> *
> *   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/
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index