Announcement

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

  • _natscale produces values that are greater than the min and less than the max?

    Hi All,

    I am getting strange results from _natscale where the r(min) is larger than the #_min and r(max) is smaller than #_max. I've tried changing the #_n -- which sometimes works....

    First, does anyone have an idea why this algorithm is getting this wrong (the r(max) is a full 5 points higher than #_max)?

    Second, is there a simple solution to fixing this?

    Thanks in advance!

    Ariel

    Code:
    _natscale 39.62556076049805  145.2605285644531 5
    
    . return list
    
    scalars:
                      r(n) =  6
                    r(min) =  40
                    r(max) =  140
                  r(delta) =  20

  • #2
    as the help file says, " _natscale returns in r() "nice" values" - and "nice" values will act the way you found; if you don't want "nice" values (e.g., for labels), then what is your goal and maybe someone can suggest something else

    Comment


    • #3
      My goal is to get values for a y or x axis of a graph that incorporates the min and max values. If not, then the graph does not look “nice”.

      Comment


      • #4
        well, <grin>, I think that you and StataCorp have different definitions of "nice"; given your goal, why not use -summarize-?

        Comment


        • #5
          <grin> indeed! I use summarize to get the min and max values and then plug them into _natscale. The problem is that I have a graph that overlays on top of another graph. If I don’t get the ylabels aligned between the two graphs then it looks anything but nice.

          Comment


          • #6
            See also nicelabels.

            SJ-22-4 gr0092 . . . . . . . . . . . . Speaking Stata: Automating axis labels
            (help nicelabels, mylabels, myticks if installed) . . . . . N. J. Cox
            Q4/22 SJ 22(4):975--995
            provides commands to handle two common problems with graph
            axis labels: decide in advance on some "nice" numbers to
            use on one or both axes and show particular labels on some
            transformed scale

            Comment


            • #7
              Hi Nick!

              I’ve read both of these excellent articles (and the articles referenced therein). Since this will be a user-written command, I was hoping to rely on official Stata commands within. That said, if I cannot get _natscale to include the min/max values on the ylabel(), I’ll likely include your -nicelabels-

              Thanks,

              Ariel

              Comment


              • #8
                Community-contributed (aka user-written) commands must ... only use official commands within??? That's a personal rule, I guess.

                There is a third way: copy code from other community-contributed commands as programs called within your ado, and acknowledge such code in the help file.

                Comment


                • #9
                  Advantages of #8

                  1. You don't commit your users to downloading the other programs too.

                  2. If the other stuff disappears from public view, you're covered.

                  3. If the other stuff changes in ways you don't want, you're covered.

                  Disadvantages of #8:

                  1. If the other stuff is buggy, it's now your fault.

                  2. If the other stuff has a bug fixed, you need to notice and to change your code.

                  Comment


                  • #10
                    Thank you, Nick. Indeed it is a personal choice not to call other user-written commands from within my user-written commands exactly because of the reasons you listed (in particular the bugs as well as incompatibility with different versions of Stata). That said, I do like your suggestion to take some of the code from another command and imbed it in my command — after validating the code, of course. I’ll give it more thought!

                    Comment

                    Working...
                    X