Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

RE: st: RE: Jittering problem

From   Nick Cox <>
To   "''" <>
Subject   RE: st: RE: Jittering problem
Date   Fri, 20 May 2011 16:28:57 +0100

Jittering has been in Stata since about Stata 2. But your program does what you need. 

qui su `varlist' if `touse'

could now be 

su `varlist' if `touse', meanonly 


Fred Wolfe

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"

 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


On Fri, May 20, 2011 at 9:13 AM, Nick Cox <> 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
> 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:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index