[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Rajesh Tharyan" <R.Tharyan@exeter.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: bihistogram |

Date |
Fri, 29 Aug 2008 21:33:41 +0100 |

Hi Austin, Sorry for the delay in getting back on this. Thank you very much for your code and your suggestions on other techniques. I was going trough your code I was starting (read trying) to write one myself when you posted yours. One of the problems I had was getting the legends to display properly. I couldn't figure out how to get the category names into a macro. I see you use this in your code qui levelsof `by', loc(bl) tokenize `bl' using the auto file and say my by variable is make . levelsof foreign, loc(bl) 0 1 . tokenize `bl' will then give me 0 and 1, how can I get it to give me domestic and foreign. I tried -decode- Decode foreign, gen(b) . levelsof b, loc(`al') `"Domestic"' `"Foreign"' I get this error msg.. . tokenize `al' varlist not allowed r(101); How can I get domestic and foreign into a local? Cheers rajesh -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Austin Nichols Sent: 26 August 2008 18:54 To: statalist@hsphsun2.harvard.edu Subject: Re: st: RE: bihistogram See also http://www.stata.com/support/faqs/graphics/gph/graphdocs/twbar3.html but I would fix the negative labels--no reason not to make them positive in both directions. Also try this program out: *! bihist 1.0 26 Aug 2008 Austin Nichols prog bihist version 8.2 syntax varname [fw aw pw], by(varname) [*] qui insp `by' if r(N_unique)!=2 { di as err "Variable `by' should have two distinct values" err 198 } loc v `varlist' tempvar x y twoway__histogram_gen `v',gen(`x' `y') `options' loc s=r(start) loc w=r(width) loc b=r(bin)+1 qui replace `x'=. qui forv i=1/`b' { replace `x'=`s'+`i'*`w'/2 if `v'>`s'+(`i'-1)*`w'&`v'<`s'+(`i')*`w' } qui replace `y'=(`v'<.) loc xl "`:var lab `v''" preserve collapse (sum) `y' [`weight'`exp'], by(`by' `x') fast qui levelsof `by', loc(bl) tokenize `bl' su `y', meanonly loc m=r(max) replace `y'=-`y' if `by'==`1' loc o=int(log10(`m')) loc M=ceil(`m'/10^`o')*10^`o' loc p=min(length("`:di `M'/3'"),length("`:di `M'/4'")) loc l "ylabel(" forv i=-`p'/`p' { loc l `"`l' `=`M'*`i'/`p'' "`=`M'*abs(`i')/`p''" "' } loc l `"`l')"' loc l `"`l' yti(Freq in `=trim("`: di %20.0gc 10^`o''")'s)"' loc l `"`l' xti(`xl')"' loc l `"`l' leg(label(1 "`:var lab `by'' = `:label (`by') `1''")"' loc l `"`l' label(2 "`:var lab `by'' = `:label (`by') `2''"))"' tw bar `y' `x' if `by'==`1' || bar `y' `x' if `by'==`2', `l' end sysuse auto, clear bihist mpg, by(for) On Tue, Aug 26, 2008 at 7:50 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > A bihistogram -- I didn't know before searching -- is a dual histogram > with one group's frequencies shown as negative. > > Rajesh found nothing, but -search histogram- points to this: > > SJ-5-2 gr0014 . . . . . . . Stata tip 20: Generating histogram bin > variables > . . . . . . . . . . . . . . . . . . . . . . . . . . . . D. A. > Harrison > Q2/05 SJ 5(2):280--281 (no > commands) > tip illustrating the use of twoway__histogram_gen for > creation of complex histograms and other graphs or tables > > The text is accessible to all via > <http://www.stata-journal.com/sjpdf.html?articlenum=gr0014> > > That includes a worked example. > > Here is another: > > sysuse auto, clear > twoway__histogram_gen mpg if foreign, width(2) start(10) freq /// > gen(freq_foreign mpg_foreign) > twoway__histogram_gen mpg if !foreign, width(2) start(10) freq /// > gen(freq_domestic mpg_domestic) > replace freq_foreign = -freq_foreign > twoway bar freq_foreign mpg_foreign, barw(2) || /// > bar freq_domestic mpg_domestic, barw(2) /// > legend(order(1 "Foreign" 2 "Domestic")) > > Nick > n.j.cox@durham.ac.uk > > Rajesh Tharyan > > Is it possible to produce a bihistogram in stata? Nothing turns up on > findit > or search. I was trying to write a program to do that. But can one get > stata > to produce histogram with -ve frequencies? > * * 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/

**References**:**st: RE: bihistogram***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: RE: bihistogram***From:*"Austin Nichols" <austinnichols@gmail.com>

- Prev by Date:
**Re: st: statalist problems** - Next by Date:
**Re: st: multicollinearity and heteroskedasticty in panel models** - Previous by thread:
**Re: st: RE: bihistogram** - Next by thread:
**Re: st: Scatterplot: Weighted markers change size** - Index(es):

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