Announcement

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

  • Help with truncation

    Dear Stata Members
    I need a help with respect to truncation and how operationally it is different from removing observations and winsorizing observations. Please note the following remarks

    ETR is defined as Income taxes paid (TXPD) divided by pretax income (PI). Firms are required to have a positive denominator, and ETR is truncated to the range [0,1]

    Code:
    Can we do something like this 
    gen ETR=TXPD/PI
    replace ETR==. if PI<0
    drop if ETR>1
    drop if ETR<0
    .
    However, all inferences are unchanged if we winsorize ETRs rather than truncating
    I have used winsor2 by Nick Cox but I am not sure how to use it here as there are no percentiles involved.

    Can someone help me here


  • #2
    Not guilty of writing winsor2 which is by someone else.

    Code:
    . ssc desc winsor2
    
    -----------------------------------------------------------------------------------------
    package winsor2 from http://fmwww.bc.edu/repec/bocode/w
    -----------------------------------------------------------------------------------------
    
    TITLE
          'WINSOR2': module to winsorize data
    
    DESCRIPTION/AUTHOR(S)
          
             winsor2 can winsorize a varlist, operate with the by prefix,
          and offers a replace option.
          
          KW: winsor
          KW: winsorize
          KW: data management
          
          Requires: Stata version 8
          
          Distribution-Date: 20201125
          
          Author: Yujun Lian, Department of Finance, Sun Yat-Sen University, China
          Support: email [email protected]
          
    
    INSTALLATION FILES                              (type net install winsor2)
          winsor2.ado
          winsor2.sthlp
    -----------------------------------------------------------------------------------------
    (type ssc install winsor2 to install)
    I don't read this brief text as anything to do with Winsorizing. As you say, the procedure does not involve percentiles.

    I can't say whether it means ignoring values outside [0, 1] or it means a different procedure, pulling back values outside that interval to be whichever is nearer 0 and 1, .

    Comment


    • #3
      Dear Nick Cox
      First, I am sorry that I misread the sentence "The winsor ado file was written by Nicholas J. Cox; Yujun Lian seemingly used the code and expanded the file to create winsor2" (Source:https://wlm.userweb.mwn.de/Stata/wstatwin.htm).
      Second, if means a different procedure, pulling back values outside that interval to be whichever is nearer 0 and 1, then you can use the replace command right. Say replace myvar=1 if myvar>1.

      Comment


      • #4
        That text in your link is correct. I haven't communicated with the author of winsor2 that I recall, but that's fine. I wrote winsor originally in 1998 and made it public because people kept asking on Statalist for Stata code to do WInsorizing, but I am not a big fan of the procedure at all.

        Note that Stata has a dedicated function for this.

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float var1
        -.2
          0
         .5
          1
        1.2
        end
        
        
        gen wanted = clip(var1, 0, 1)
        
        list 
        
             +---------------+
             | var1   wanted |
             |---------------|
          1. |  -.2        0 |
          2. |    0        0 |
          3. |   .5       .5 |
          4. |    1        1 |
          5. |  1.2        1 |
             +---------------+

        Comment


        • #5
          Dear Nick Cox
          Thanks for this excellent help as I didn't know about -clip- function and it saves my time a lot! Thanks a ton!

          Comment

          Working...
          X