Announcement

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

  • Adjusting Decimals and Separators

    Dear Friends,

    Here, I provide an example of my data. These are China and the USA's global aid flow between 2000 and 2017. I want to transform my "chnodalilike" variable in accordance with the "usaglobal". For instance, USA provided 30107 million dollars (30 billion dollars) in 2009, whereas China provided 6399 million US Dollars. However, I want to change China's numbers from "6399943653.353926" to "6399.94". How can I do that without intervening manually? My all dataset are in "xxxx.yy" shape. I inserted new numbers as seen in 2001 and 2002 for China.

    Thank you so much,

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float year double chnodalilike float usaglobal
    2001        2682.69 11800.44
    2002        1672.05 14825.64
    2003 2603173584.2821565 20162.23
    2004  999300966.6191502 21766.16
    2005  2554538493.740531  33225.2
    2006  3364553638.661135 26662.06
    2007 4095723127.9216104 23186.91
    2008 3307489831.3064613  28231.1
    2009  6399943653.353926 30107.46
    2010 15628045131.597378 30626.26
    2011  4911782485.887178 31598.51
    2012  6213166525.501058 28892.44
    2013 7856521605.2097645 29442.31
    2014  6161842113.101356 30161.69
    2015  6275824010.130476 28934.51
    2016 10349380752.750761 30678.79
    2017  6832654928.216418 31649.52
    2018                  0  30837.4
    2019                  0 29161.39
    2020                  0 29673.06
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
       .                  .        .
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 81 out of 122 observations

  • #2
    If you mean that China's figures are a mixture of amounts in millions and absolute amounts, perhaps:

    Code:
    replace chnodalilike= chnodalilike/1e+6 if chnodalilike>1e+6
    Res.:

    Code:
    . l in 1/17, sep(0)
    
         +-----------------------------+
         | year   chnodal~e   usaglo~l |
         |-----------------------------|
      1. | 2001     2682.69   11800.44 |
      2. | 2002     1672.05   14825.64 |
      3. | 2003   2603.1736   20162.23 |
      4. | 2004   999.30097   21766.16 |
      5. | 2005   2554.5385    33225.2 |
      6. | 2006   3364.5536   26662.06 |
      7. | 2007   4095.7231   23186.91 |
      8. | 2008   3307.4898    28231.1 |
      9. | 2009   6399.9437   30107.46 |
     10. | 2010   15628.045   30626.26 |
     11. | 2011   4911.7825   31598.51 |
     12. | 2012   6213.1665   28892.44 |
     13. | 2013   7856.5216   29442.31 |
     14. | 2014   6161.8421   30161.69 |
     15. | 2015    6275.824   28934.51 |
     16. | 2016   10349.381   30678.79 |
     17. | 2017   6832.6549   31649.52 |
         +-----------------------------+

    Comment


    • #3
      So you want to convert figures that are given in USD to figures given in millions of USD. To do that you divide by one million. For your example data, which shows only positive values, and includes figures manually added that are already in millions of USD, the following demonstrates the approach.
      Code:
      . replace chnodalilike = chnodalilike/1000000 if chnodalilike>100000 & !missing(chnodalilike)
      (15 real changes made)
      
      . list in 1/21, clean noobs abbreviate(12)
      
          year   chnodalilike   usaglobal  
          2001        2682.69    11800.44  
          2002        1672.05    14825.64  
          2003      2603.1736    20162.23  
          2004      999.30097    21766.16  
          2005      2554.5385     33225.2  
          2006      3364.5536    26662.06  
          2007      4095.7231    23186.91  
          2008      3307.4898     28231.1  
          2009      6399.9437    30107.46  
          2010      15628.045    30626.26  
          2011      4911.7825    31598.51  
          2012      6213.1665    28892.44  
          2013      7856.5216    29442.31  
          2014      6161.8421    30161.69  
          2015       6275.824    28934.51  
          2016      10349.381    30678.79  
          2017      6832.6549    31649.52  
          2018              0     30837.4  
          2019              0    29161.39  
          2020              0    29673.06  
             .              .           .  
      
      . // perhaps you want them to display with just two decimal points
      . format %9.2f chnodalilike usaglobal
      
      . list in 1/21, clean noobs abbreviate(12)
      
          year   chnodalilike   usaglobal  
          2001        2682.69    11800.44  
          2002        1672.05    14825.64  
          2003        2603.17    20162.23  
          2004         999.30    21766.16  
          2005        2554.54    33225.20  
          2006        3364.55    26662.06  
          2007        4095.72    23186.91  
          2008        3307.49    28231.10  
          2009        6399.94    30107.46  
          2010       15628.05    30626.26  
          2011        4911.78    31598.51  
          2012        6213.17    28892.44  
          2013        7856.52    29442.31  
          2014        6161.84    30161.69  
          2015        6275.82    28934.51  
          2016       10349.38    30678.79  
          2017        6832.65    31649.52  
          2018           0.00    30837.40  
          2019           0.00    29161.39  
          2020           0.00    29673.06  
             .              .           .

      Comment


      • #4
        Thank you so much Andrew Musau

        Yes, I am definitely looking for this. But, my main point was related to adjusting decimals after converting figures. I couldn't formulate my question clearly.

        William Lisowski thank you so much for this.

        Best,



        Comment

        Working...
        X