Announcement

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

  • Displaying results in different colors

    I am trying to display some results using different colors:
    Code:
    display "{green: result}"
    However, only black and red appears to be working.

    Is it possible to display different colors in the results window without changing Stata's preferences?

  • #2
    You may use the option "as text" for green, "as result" for yellow, and "as error" for red, as shown here.

    Best regards,

    Marcos

    Comment


    • #3
      You may use the option "as text" for green, "as result" for yellow, and "as error" for red, as shown here.
      Unfortunately, this only works if you change the default colors in the preferences.

      Comment


      • #4
        Old syntax such as

        Code:
        di in green "frog"
        has been ignored by Stata for some time now (since Stata 8? 9?). Although you can take the line that Stata should either obey or issue an error message, I suspect that it's easier for more users that Stata just ignores it, as otherwise many old programs and do files would be broken.

        The only exception I know is that Stata will use red for anything stated to be an error

        Code:
        di as err "wear red if it suits you!"

        Comment


        • #5
          Note that display as red works as intended but everything else is ignored, a decision which is really absurd. This is clearly a step backwards. Displaying results in different colors is extremely useful in some applications.

          Comment


          • #6
            "really absurd"? The fact is that this decision goes back several versions. You can call it inconsistent and I will agree, but it seems to me to be a pragmatic decision by StataCorp that in this case people are not bitten by what from most points of view is a minor change to Stata syntax

            For example, it is a widespread convention now that blue means clickable, but display in blue as Stata syntax long predates that. I think that Stata users are better off if such a directive in old code is just ignored. It no longer means what it used to mean, namely that blue is an arbitrary decorative colour.

            The history of this question on Statalist is, so far as I am aware, that it has almost never been asked over the last decade or so, implying that Stata users haven't been troubled by it, or even noticed.

            Comment


            • #7
              Originally posted by Belinda Foster View Post
              Note that display as red works as intended but everything else is ignored, a decision which is really absurd. This is clearly a step backwards. Displaying results in different colors is extremely useful in some applications.
              Do you believe you can't use colors? That is incorrect. It is only that you specify the type of output, and the color depends on the scheme used by the user. That is a step forward, now users can decide their own preferred scheme and it still won't break any program. For example, I like the classic output with a black background. If you could output text in black then it would become invisible. Now you name it input, and it will turn black in the default scheme and white in classic.
              ---------------------------------
              Maarten L. Buis
              University of Konstanz
              Department of history and sociology
              box 40
              78457 Konstanz
              Germany
              http://www.maartenbuis.nl
              ---------------------------------

              Comment


              • #8
                Nick Cox What I meant by saying "really absurd" is not the change in syntax (which i agree it is inconsistent albeit trivial), but the decision from StataCorp not to offer a more flexible way to present results using different colors.

                Maarten Buis The fact of the matter is that the "scheme" you are referring to is set by the preferences and it is not programmable. At least, that is my understanding. So, to my knowledge, assigning colors to each output type cannot be done on-the-fly. From a user's perspective I guess you are correct that this change was a step forward, but from a programmer's point of view it offer very little flexibility. Ideally, a programmer should be able to not only be able to change dynamically certain output types, but any specific text object desired.
                Last edited by Belinda Foster; 17 Apr 2017, 07:22.

                Comment


                • #9
                  I don't worry about displaying in colours myself except that I want errors to be shown conventionally and clickable links shown as such. But that's just me.

                  What a programmable change such as you request would imply is, I think, that the whole set of colours could change on the fly; that is while a window was being displayed. I don't know how that would work.

                  Comment


                  • #10
                    Originally posted by Belinda Foster View Post
                    From a user's perspective I guess you are correct that this change was a step forward, but from a programmer's point of view it offer very little flexibility. Ideally, a programmer should be able to not only be able to change dynamically certain output types, but any specific text object desired.
                    No, the advantage is for programmers: this way we can write output that is always readable without knowing which scheme is chosen by all users. The advantage to the user is only that this practice leads to better programs.
                    ---------------------------------
                    Maarten L. Buis
                    University of Konstanz
                    Department of history and sociology
                    box 40
                    78457 Konstanz
                    Germany
                    http://www.maartenbuis.nl
                    ---------------------------------

                    Comment


                    • #11
                      To illustrate this point, here is how I would use colors in Stata (In fact, in this example I am more inconsistent than I would usually be in the way I work on multiple lines in the program without introducing a linebreak in the output, but that is just to illustrate multiple ways of doing so):

                      Code:
                      clear all
                      
                      program define foo
                          di as txt    "{p}Een ding heb ik nooit begrepen: "        _continue
                          di as result    "waarom heeft een zebra strepen, "              ///
                             as error     "en geen stippels," as result " en geen ruit? " ///
                             as input     "waarom koos hij strepen uit?{p_end}"
                      end
                      
                      foo
                      The point is that the programmer names what kind of output the text is, and the scheme determines the color it gives it. This ensures that the user is presented with output that is consistent with what she or he is used to. I am used to seeing results (parameter estimates, p-values, etc) in yellow, and this way that is what I will get. People who use the default scheme are used to seeing the result in black bold font, and that is what they will get. The first goal of output in a program like Stata is that it is easily decodable by the user, and using consistent formatting is an important way of attaining that goal. This way of programming will spit the results out in the format that is consistent with the user's experience, without the programmer having to access the display scheme used by the user (if that is available) and add a long if-else structure, which is guaranteed to introduce bugs. This is why I consider this a step forward, instead of backwards.
                      ---------------------------------
                      Maarten L. Buis
                      University of Konstanz
                      Department of history and sociology
                      box 40
                      78457 Konstanz
                      Germany
                      http://www.maartenbuis.nl
                      ---------------------------------

                      Comment


                      • #12
                        Maarten Buis I did not disagree with your point. And the example you provide makes sense. However, this is all dependent on the preferences set by the user in Stata and the output is not fully programmable by the programmer. Also, when there is a large number of results displayed, in my opinion, it is beneficial to be able to display certain values using a different color on-the-fly. This is not possible unless the programmer uses red, which can be counter-intuitive.

                        Comment


                        • #13
                          Hello,
                          for regulatory studies we conduct, we translate the results into a pdf file and annex it to our study reports (paperwork). Colors in the translated results (like in do files) would allow us to have a more readable documents for our sponsors and authorities. that's just why I'm looking for this!

                          Comment

                          Working...
                          X