Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting maximum from histograms?

    Hello,

    I am seeking assistance with overlaying a histogram graph on top of a line graph. While I understand this can be achieved easily using twoway and manipulating different x and y axes, I have a specific requirement: I want the histogram to occupy only 1/4 of the y-axis height.

    In theory, I can accomplish this using gr_edit by determining the maximum of the y-axis and then multiplying it by 4. However, since I need to generate numerous graphs automatically, manual intervention to determine the maximum of the y-axis for each graph is impractical.

    Is there a method to automatically determine the maximum of the y-axis? Alternatively, do you know of any workarounds I could utilize?

    Here's an example of the code I'm currently attempting to use, where 0.428 represents the maximum of the y-axis:

    Code:
    clear
    
    set obs 1000
    set seed 12
    gen dist=rnormal()
    sort dist
    gen yvar=dist^2
    
    tw (line yvar dist) (hist dist, xaxis(2) yaxis(2))
    gr_edit .yaxis2.plotregion.yscale.curmax = 0.428*4
    Any help would be greatly appreciated!

  • #2
    Code:
    help twoway__histogram_gen
    twoway__histogram_gen gets you the variables that
    Code:
    twoway histogram
    would use.

    Comment


    • #3
      That's great!

      Thanks a lot Nick!

      Comment


      • #4
        Yet another example of why many/most/all undocumented commands, like twoway__histogram_gen, should be reconsidered for documentation.

        Code:
        help undocumented
        For years I have kvetched that Stata's claim about "usually interesting" in the help file
        An undocumented command is a command of very limited interest, usually interesting only to Stata programmers, and is used by StataCorp in developing Stata.
        is irrelevant since some users (this thread being a case in point) would benefit from documentation.

        I conjecture that the majority of Stata users are not even aware that such undocumented commands exist.

        Since the cost of documentation is essentially zero (hardcopy documentation pagespace is no longer an important consideration) and the benefits of documentation are evidently positive, it's hard for me to understand the continued reliance on undocumented commands.

        Comment


        • #5
          I don't need to explain to an economist that there are always costs and always trade-offs. A long time ago, there was an intention to document the internals of Stata's graphics in more detail, but that didn't materialise. The guess appears to have been that the task would lock up one key developer for a couple of years, to write something that perhaps only about three hyper-keen user-programmers would ever read.

          twoway__histogram_gen is also something documented in the Stata Journal.

          The trade-off here is a bit simpler, but undocumented here is Pickwickian Stata jargon that just means that there isn't a manual entry, but there is a help file.

          It's the non-documented commands you should be kvetching about. About one it has been said you should use it if you come across it, work out that what it does is something you need, but also realise how dangerous it could be,

          The larger question of who reads the help or the manuals and how much they read either is interesting and important. Some posts on the internet seems to imply that some people only ever Google or rely on AI.

          Comment

          Working...
          X