Announcement

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

  • Creating upper and lower thresholds

    Hi,

    I need help if someone can help me as soon. The following is my data set:

    Country_Name id Country_Code Exchange_Rate tax_rate tax_threshold
    Albania 1 ALB 119.0997 0 360000
    Albania 2 ALB 119.0997 .13 1800000
    Albania 3 ALB 119.0997 .23
    Albania 4 ALB 119.0997
    Albania 5 ALB 119.0997
    Albania 6 ALB 119.0997
    Albania 7 ALB 119.0997
    Albania 8 ALB 119.0997
    Albania 9 ALB 119.0997
    Albania 10 ALB 119.0997
    Albania 11 ALB 119.0997
    Albania 12 ALB 119.0997
    Albania 13 ALB 119.0997
    Albania 14 ALB 119.0997
    Albania 15 ALB 119.0997
    Albania 16 ALB 119.0997
    Albania 17 ALB 119.0997
    Albania 18 ALB 119.0997
    Albania 19 ALB 119.0997
    Albania 20 ALB 119.0997
    Albania 21 ALB 119.0997
    Albania 22 ALB 119.0997
    Albania 23 ALB 119.0997
    Algeria 1 DZA 110.973 0 120000
    Algeria 2 DZA 110.973 .2 360000
    Algeria 3 DZA 110.973 .3 1440000
    Algeria 4 DZA 110.973 .35
    Algeria 5 DZA 110.973
    Algeria 6 DZA 110.973
    Algeria 7 DZA 110.973
    Algeria 8 DZA 110.973
    Algeria 9 DZA 110.973
    Algeria 10 DZA 110.973
    Algeria 11 DZA 110.973


    I want to change my tax_threshold variable to:

    threshold_low threshold_high

    0 360000


    360000 1800000

    Can you please help me? Thank you!= in advance!


  • #2
    On your previous topic I suggest you review the Statalist FAQ linked to from the top of the page to improve your presentation of your problems.

    I will again give that advice, emphasizing the presentation of example data.

    You should use the dataex command to present example data. If you are running version 15.1 or a fully updated version 14.2, dataex is already part of your official Stata installation. If not, run ssc install dataex to get it. Either way, run help dataex and read the simple instructions for using it. dataex will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use dataex.

    With that said, the following example should start you in a useful direction.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str7 country_name byte id str3 country_code float(exchange_rate tax_rate) long tax_threshold
    "Albania"  1 "ALB" 119.0997   0  360000
    "Albania"  2 "ALB" 119.0997 .13 1800000
    "Albania"  3 "ALB" 119.0997 .23       .
    "Albania"  4 "ALB" 119.0997   .       .
    "Albania"  5 "ALB" 119.0997   .       .
    "Algeria"  1 "DZA"  110.973   0  120000
    "Algeria"  2 "DZA"  110.973  .2  360000
    "Algeria"  3 "DZA"  110.973  .3 1440000
    "Algeria"  4 "DZA"  110.973 .35       .
    "Algeria"  5 "DZA"  110.973   .       .
    end
    
    generate threshold_low = .
    generate threshold_high = .
    bysort country_name (id): replace threshold_high = tax_threshold
    bysort country_name (id): replace threshold_low = threshold_high[_n-1]
    bysort country_name (id): replace threshold_low = 0 if id==1
    list, noobs sepby(country_name)
    Code:
    . list, noobs sepby(country_name)
    
      +---------------------------------------------------------------------------------+
      | count~me   id   count~de   exchan~e   tax_rate   tax_th~d   thresh~w   thresh~h |
      |---------------------------------------------------------------------------------|
      |  Albania    1        ALB   119.0997          0     360000          0     360000 |
      |  Albania    2        ALB   119.0997        .13    1800000     360000    1800000 |
      |  Albania    3        ALB   119.0997        .23          .    1800000          . |
      |  Albania    4        ALB   119.0997          .          .          .          . |
      |  Albania    5        ALB   119.0997          .          .          .          . |
      |---------------------------------------------------------------------------------|
      |  Algeria    1        DZA    110.973          0     120000          0     120000 |
      |  Algeria    2        DZA    110.973         .2     360000     120000     360000 |
      |  Algeria    3        DZA    110.973         .3    1440000     360000    1440000 |
      |  Algeria    4        DZA    110.973        .35          .    1440000          . |
      |  Algeria    5        DZA    110.973          .          .          .          . |
      +---------------------------------------------------------------------------------+
    Last edited by William Lisowski; 03 Apr 2019, 15:05.

    Comment

    Working...
    X