Announcement

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

  • Mathematical function ceil

    Hi guys,

    I generated the variable "revenue" in steps of 50 Mio. After that I want to generate the corresponding histogram, but it only shows me positive revenue. Since I have negative an positive revenue, how can I change the code?

    So far I got:
    Code:
    gen revenue = 50 * ceil(WC01001/50e6)

  • #2
    Hmm, my simulation (below) doesn't have that problem. Show us your exact histogram command, and also the results of:
    Code:
    count
    count if (revenue <=0)
    count if (WC01001 <=0)
    And, see if my simulation gives a result like what you would expect:
    Code:
    clear
    set seed 47543
    set obs 1000
    gen W = (-500e6 + runiform() * 1e9)
    gen revenue = 50 * ceil(W/50e6)
    histogram W


    Comment


    • #3
      Note that zero is necessarily for upper limit for (-50, 0], for example.

      Comment


      • #4
        My command is:
        Code:
        summarize WC01001
        gen revenue = 50 * ceil(WC01001/50e6)
        hist revenue, frequency
        I tired your command Mike, but it doesn't show me the negative revenue either.

        I also tried count commands
        count = 175,278
        count if (revenue <=0) = 8,727
        count if (WC01001 <=0) = 159



        Comment


        • #5
          Please show the result of

          Code:
          summarize revenue 

          Comment


          • #6
            Variable Obs Mean Std. Dev. Min Max

            WC01001 154,091 3.47e+07 4.27e+07 -85811 1.07e+09





            Comment


            • #7
              The fact that you can't see any negative values of revenue with the simulated-data example I showed surprises me, and makes me wonder if we are interpreting the histogram differently. I'm out of ideas here.



              Comment


              • #8
                It's simple and as already commented . The bin width here is 50 million and -- even though the units shown are millions -- the use of ceil() means that each bin is represented by its upper limit. To wit,

                Code:
                .   display 50 * ceil(-85811/50e6)
                0
                shows that even the minimum (the most negative) is in the bin with upper limit zero. Nothing wrong here. All the negative values in the data are bundled with exact zeros, if any.

                Comment


                • #9
                  Code:
                      Variable |        Obs        Mean    Std. Dev.       Min        Max
                  -------------+---------------------------------------------------------
                       WC01001 |    154,091    3.47e+07     4.27e+07     -85811   1.07e+09
                  tells us that the minimum value of WC01001 is -85811.

                  Code:
                  . generate WC01001 = -85811
                  
                  . generate revenue = 50 * ceil(WC01001/50e6)
                  
                  . list
                  
                       +-------------------+
                       | WC01001   revenue |
                       |-------------------|
                    1. |  -85811         0 |
                       +-------------------+
                  tells us that the reason you see no values of revenue < 0 in your plot is because all your values of WC01001< 0 will become revenue = 0.

                  To remedy this problem, I tried
                  Code:
                  generate revenue = WC01001/1e6
                  hist revenue, frequency width(50) start(-50)
                  which I think achieves your objectives of expressing revenue in millions with bins 50 million wide.

                  Comment


                  • #10
                    Thanks guys, that solves the problem.

                    Comment

                    Working...
                    X