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: tsline: narrowing the range using range()


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: tsline: narrowing the range using range()
Date   Thu, 22 Aug 2013 20:34:12 -0500

The -twoway, cmissing()- option may be helpful.  Below are a few ways
to impose line breaks:

clear
set obs 25
set seed 8222013
gen t = _n
gen y = runiform()*20
replace y = runiform()*100 + 20 if runiform() < .2
gen y2 = y
replace y2 = . if y2 > 20
twoway connect y t, name(alldata,replace)

//Line break with cmissing() option
twoway connect y2 t , cmissing(n) name(narrow1,replace)

twoway connect y2 t , cmissing(n)  color(blue) ///
  || connect y2 t , cmissing(y) color(blue) lp(dot) ///
   ||, legend(order(1 "y without spikes")) name(narrow2,replace)

//Line break with overlayed white points
ipolate y2 t ,gen(y3)
twoway connect y2 t  ///
  || scatter y3 t if y2 ==. , msize(*4) mc(white)  ///
  ||, legend(order(1 "y without spikes")) name(narrow3,replace)



Scott


On Thu, Aug 22, 2013 at 3:53 PM, Nick Cox <[email protected]> wrote:
> See http://www.stata.com/support/faqs/graphics/scale-breaks/ (second part)
> Nick
> [email protected]
>
>
> On 22 August 2013 21:15, Daniel Pollmann <[email protected]> wrote:
>> I am plotting a time series using tsline. The time series takes values in
>> [0,100], but I would like to restrict the range of the y-axis to [0,20], such
>> that the time series would spike out of the plot at some point and return
>> later.
>>
>> The following code does not enforce the specified plot range when it is not a
>> superset of the range of the data:
>>
>> tsline myseries, yscale(range(0 20))
>>
>> In other words, if I have data points equal to 100, Stata widens the range
>> automatically to accommodate these points. Winter (Stata J., 2005) describes
>> the problem:
>>
>> "To determine the range of an axis, Stata begins with the minimum and maximum
>> of the data. Then it will widen (but never narrow) the axis range as instructed
>> by
>> range(). Finally, it will widen the axis if necessary to accommodate any axis
>> labels."
>>
>> (http://www.stata-journal.com/sjpdf.html?articlenum=gr0019)
>>
>> I would like to be able to narrow the axis range, either using range() or some
>> other way. If there is an intended way to do this, it would be great to hear
>> about it, but I am also open to creative fixes and hacks. I've tried censoring
>> and truncating the data myself, but neither option produces nice-looking
>> results.
>>
>> Thanks,
>>
>> Daniel
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index