Announcement

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

  • Help with command

    Hi there!

    I need help with the following equation

    X = log(change in cost ÷ change in sale)i,T - log(change in cost ÷ change in sale)i,T

    T, T ϵ (t, …., t-3)

    Where T is the most recent of the last four quarters with a decrease in sales and T is the most recent of the last four quarters with an increase in sales. I can’t comprehend how to go about with the command on Stata for this.

    In the variable list saleC is the change in sale, costC is change in cost, saleD =1 means the quarter with decrease in sale from prior quarter and saleI=1 means the quarter with increase in sale from prior quarter


    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(gvkey datadate) double(ibq saleq) float(cost saleC costC saleD saleI)
    1000 5568 .19 11.295 11.105 -.102 -.013000488 1 .
    1000 5659 .875 14.441 13.566 3.146 2.4610004 . 1
    1000 5751 .613 13.122 12.509 -1.319 -1.0570002 1 .
    1000 5843 .606 12.334 11.728 -.788 -.7810001 1 .
    1000 5934 .726 16.226 15.5 3.892 3.772 . 1
    1000 6025 1.603 19.637 18.034 3.411 2.5340004 . 1
    1000 6117 .561 14.733 14.172 -4.904 -3.8620005 1 .
    1000 6209 .544 15.818 15.274 1.085 1.1020002 . 1
    1000 6299 .563 18.014 17.451 2.196 2.177 . 1
    1000 6390 .975 21.203 20.228 3.189 2.7770004 . 1
    1000 6482 .484 19.359 18.875 -1.844 -1.3530006 1 .
    1000 6664 .173 18.92 18.747 -.439 -.12800026 1 .
    1001 8490 .07 4.921 4.851 . . . 1
    1001 8581 .452 5.859 5.407 .938 .55600023 . 1
    1001 8673 .364 6.449 6.085 .59 .678 . 1
    1001 8765 .249 8.166 7.917 1.717 1.8319998 . 1
    1001 8856 .257 6.434 6.177 -1.732 -1.7399998 1 .
    1001 8947 .425 7.559 7.134 1.125 .9569998 . 1
    1001 9039 .403 8.058 7.655 .499 .5210004 . 1
    1001 9131 .053 9.956 9.903 1.898 2.2479997 . 1
    1001 9221 .292 7.865 7.573 -2.091 -2.33 1 .
    1001 9312 .5 9.348 8.848 1.483 1.2749996 . 1
    1001 9404 1.257 16.327 15.07 6.979 6.222 . 1
    1001 9496 .527 20.258 19.731 3.931 4.661001 . 1
    1001 9586 .164 13.997 13.833 -6.261 -5.898001 1 .
    1003 8400 .929 12.748 11.819 . . . 1
    1003 8490 .137 2.647 2.51 -10.101 -9.309 1 .
    1003 8581 .331 3.522 3.191 .875 .681 . 1
    1003 8673 .179 2.963 2.784 -.559 -.4070001 1 .
    1003 8765 .403 4.661 4.258 1.698 1.474 . 1
    1003 8856 .068 2.419 2.351 -2.242 -1.907 1 .
    1003 8947 .074 2.853 2.779 .434 .428 . 1
    1003 9039 .119 3.241 3.122 .388 .3429999 . 1
    1003 9131 .126 5.316 5.19 2.075 2.068 . 1
    1003 9251 .041 2.761 2.72 -2.555 -2.47 1 .
    1003 9435 .094 7.425 7.331 4.664 4.611 . 1
    1003 9527 .181 8.76 8.579 1.335 1.2480006 . 1
    1003 9616 .072 7.392 7.32 -1.368 -1.2590003 1 .
    1003 9800 .148 10.174 10.026 2.782 2.706 . 1
    1003 9892 .599 10.881 10.282 .707 .25599957 . 1
    1003 9981 .135 8.852 8.717 -2.029 -1.5649996 1 .
    end

  • #2
    So, the preliminary step needed is to extract quarterly dates from the variable datadate. Also saleD and saleI were mis-generated as 1/., but to work smoothly as logical variables in Stata they need to be 1/0. So we fix that. Next we calculate the two terms of the equation that defines X. Then, -rangestat- picks the most recent values of those terms within the four-quarter window of interest. Finally, we subtract the terms to get X

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(gvkey datadate) double(ibq saleq) float(cost saleC costC saleD saleI)
    1000 5568 .19 11.295 11.105 -.102 -.013000488 1 .
    1000 5659 .875 14.441 13.566 3.146 2.4610004 . 1
    1000 5751 .613 13.122 12.509 -1.319 -1.0570002 1 .
    1000 5843 .606 12.334 11.728 -.788 -.7810001 1 .
    1000 5934 .726 16.226 15.5 3.892 3.772 . 1
    1000 6025 1.603 19.637 18.034 3.411 2.5340004 . 1
    1000 6117 .561 14.733 14.172 -4.904 -3.8620005 1 .
    1000 6209 .544 15.818 15.274 1.085 1.1020002 . 1
    1000 6299 .563 18.014 17.451 2.196 2.177 . 1
    1000 6390 .975 21.203 20.228 3.189 2.7770004 . 1
    1000 6482 .484 19.359 18.875 -1.844 -1.3530006 1 .
    1000 6664 .173 18.92 18.747 -.439 -.12800026 1 .
    1001 8490 .07 4.921 4.851 . . . 1
    1001 8581 .452 5.859 5.407 .938 .55600023 . 1
    1001 8673 .364 6.449 6.085 .59 .678 . 1
    1001 8765 .249 8.166 7.917 1.717 1.8319998 . 1
    1001 8856 .257 6.434 6.177 -1.732 -1.7399998 1 .
    1001 8947 .425 7.559 7.134 1.125 .9569998 . 1
    1001 9039 .403 8.058 7.655 .499 .5210004 . 1
    1001 9131 .053 9.956 9.903 1.898 2.2479997 . 1
    1001 9221 .292 7.865 7.573 -2.091 -2.33 1 .
    1001 9312 .5 9.348 8.848 1.483 1.2749996 . 1
    1001 9404 1.257 16.327 15.07 6.979 6.222 . 1
    1001 9496 .527 20.258 19.731 3.931 4.661001 . 1
    1001 9586 .164 13.997 13.833 -6.261 -5.898001 1 .
    1003 8400 .929 12.748 11.819 . . . 1
    1003 8490 .137 2.647 2.51 -10.101 -9.309 1 .
    1003 8581 .331 3.522 3.191 .875 .681 . 1
    1003 8673 .179 2.963 2.784 -.559 -.4070001 1 .
    1003 8765 .403 4.661 4.258 1.698 1.474 . 1
    1003 8856 .068 2.419 2.351 -2.242 -1.907 1 .
    1003 8947 .074 2.853 2.779 .434 .428 . 1
    1003 9039 .119 3.241 3.122 .388 .3429999 . 1
    1003 9131 .126 5.316 5.19 2.075 2.068 . 1
    1003 9251 .041 2.761 2.72 -2.555 -2.47 1 .
    1003 9435 .094 7.425 7.331 4.664 4.611 . 1
    1003 9527 .181 8.76 8.579 1.335 1.2480006 . 1
    1003 9616 .072 7.392 7.32 -1.368 -1.2590003 1 .
    1003 9800 .148 10.174 10.026 2.782 2.706 . 1
    1003 9892 .599 10.881 10.282 .707 .25599957 . 1
    1003 9981 .135 8.852 8.717 -2.029 -1.5649996 1 .
    end
    format datadate %td
    
    //    EXTRACT QUAERTERLY DATES FROM DATADATE
    gen int qdate = qofd(datadate)
    format qdate %tq
    
    //    FIX SALED AND SALEI SO THEY CAN BE USED LOGICALLY
    replace saleD = 0 if missing(saleD)
    replace saleI = 0 if missing(saleI)
    
    //    CALCULATE THE TWO TERMS OF X IN EACH OBSERVATION
    gen xtbar = log(costC/saleC) if saleD
    gen xt = log(costC/saleC) if saleI
    
    //    ORDER THE OBSERVATIONS CHRONOLOGICALLY WITHIN GVKEY
    sort gvkey qdate datadate
    rangestat (lastnm) xtbar xt, by(gvkey) interval(qdate -3 0)
    
    gen X = xtbar - xt
    To run this, you need to install the -rangestat- command if you do not already have it. It is written by Robert Picard, Nick Cox, and Roberto Ferrer, and is available from SSC.

    Comment


    • #3
      I just want to note that this X equation looks very odd to me. Are you sure it's right? I say this because

      1. If you have four consecutive quarters of increasing sales, or four consecutive quarters of decreasing sales, then you will never have a T_, or a T there, and X will be undefined.

      2. In order for X to be defined, both of those logarithms have to be defined, which means that CostC and SaleC must always have the same sign. I would love to know how any business manages to guarantee that costs never go up when sales go down! Where do I buy their stock?

      Comment


      • #4
        Thank you so much Clyde for step-by-step command and guidance. Shouldn't gen X be following
        gen X = xtbar_lastnm - xt_lastnm However, I think in that case the values X generates does not fulfill the rational.
        This is based on a model from the following paper

        Weiss, D. (2010). Cost behavior and analysts’ earnings forecasts. The Accounting Review, 85(4), 1441-1471. (model is in page 8).

        the paper states that "sticky (x in the above equation) is defined as the difference in the cost function slope between the two most recent quarters from quarter t-3 through quarter t, such that sales decrease in one quarter and increase in the other. If costs are sticky, meaning that they increase more when activity rises than they decrease when activity falls by an equivalent amount, then the proposed measure has a negative value. A lower value of sticky expresses more sticky cost behavior.7 That is, a negative (positive) value of sticky indicates that managers are less (more) inclined to respond to sales drops by reducing costs than they are to increase costs when sales rise (Weiss, 2010).

        Comment


        • #5
          Shouldn't gen X be following gen X = xtbar_lastnm - xt_lastnm
          Yes, you are absolutely right about that. Sorry for that error.

          However, I think in that case the values X generates does not fulfill the rational.
          I don't know what to tell you here. With your correction to the final -gen X = - command, the code does implement the equation correctly. I am not an economist, nor an accountant, nor a business person of any kind; I am an epidemiologist with a strong mathematical inclination. I'm not sure I grasp the concept that the Weiss paper is trying to get at wit X, so I can't really say whether X is a sensible way to measure it or not. In #3 I did express some reservations about it myself based on mathematical considerations. You seem to be expressing other concerns about it.

          All I can tell you is that the code correctly implements the equation. If you have concerns that the equation itself is wrong, I think you have to take that up with others in your discipline. Or perhaps other Forum members with expertise in this area will comment (I hope).

          Comment


          • #6
            Once again thank you Clyde for your response, it was indeed very helpful. Without your help I couldn't have calculated X. And I have seen the logic in #3 which is absolutely correct but with my limited understanding I have concerns about the final values of X. I have emailed the authors with sample calculations and command, fingers crossed if any of them extends their help or any other forum member.

            Comment

            Working...
            X