Announcement

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

  • How to replace observation values by other observations; GGDC 10 sector database


    Countrycode Variable -----Year ---Agriculture Mining Sum ShareAgriculture
    EGY------------- value----- ----1970----- 5 -------------10------- 15 -------5/15
    EGY------------- value----- ----1970----- 6 -------------11-------- 17 -------6/17
    EGY------------- employment 1971 -----1 --------------2 ----------3------- 1/3
    EGY------------- employment 1971 -----1--------------- 2--------- 3 --------1/3

    Hello,

    I would appreciate advice on the following issue;
    The table above is a simplified illustration from the GGDC 10 sector database, only using data on 2 sectors.
    under the variable 'Variable' it lists value, which is the value added for all sectors, and it lists employment for all sectors as seperate observations.
    I created a variable ShareAgriculture, which is the agriculture's share of the Sum.

    What I want to achieve is to replace the ShareAgriculture values where Variable = 'value' by the observation where Variable is = 'employment', because I am only interested in employment shares, not in value shares, and I want them to be in the same observations that list values of the sectors. Moreover, i want to do this for all observations where the combination of countrycode and year match.

    Thanks in advance for help!

  • #2
    This can be done in place, but you would be better off with a different data layout. Before we get there, you pose two problems.

    1. As you have not used dataex as we request, which data types you are using is unclear. For example, it's ambiguous whether you have string values or numeric values with value labels, or what the last variable is held as.

    2. Your example makes limited sense even schematically as you have duplicates on Countrycode Year Variable

    With some guesses, I get this layout, after which your share calculation is easy.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3 Countrycode str10 Variable int Year byte(Agriculture Mining Sum)
    "EGY" "value"      1970 5 10 15
    "EGY" "value"      1971 6 11 17
    "EGY" "employment" 1970 1  2  3
    "EGY" "employment" 1971 1  2  3
    end
    
    reshape wide Agriculture Mining Sum, i(Countrycode Year) j(Variable) string
    (note: j = employment value)
    
    Data                               long   ->   wide
    ----------------------------------------------------------------------------
    > -
    Number of obs.                        4   ->       2
    Number of variables                   6   ->       8
    j variable (2 values)          Variable   ->   (dropped)
    xij variables:
                                Agriculture   ->   Agricultureemployment Agriculturevalue
                                     Mining   ->   Miningemployment Miningvalue
                                        Sum   ->   Sumemployment Sumvalue
    -----------------------------------------------------------------------------
    
    . l
    
         +-------------------------------------------------------------+
      1. | Countr~e | Year | Agricu~t | Mining~t | Sumemp~t | Agricu~e |
         |      EGY | 1970 |        1 |        2 |        3 |        5 |
         |-------------------------------------------------------------|
         |           Mining~e           |           Sumvalue           |
         |                 10           |                 15           |
         +-------------------------------------------------------------+
    
         +-------------------------------------------------------------+
      2. | Countr~e | Year | Agricu~t | Mining~t | Sumemp~t | Agricu~e |
         |      EGY | 1971 |        1 |        2 |        3 |        6 |
         |-------------------------------------------------------------|
         |           Mining~e           |           Sumvalue           |
         |                 11           |                 17           |
         +-------------------------------------------------------------+
    
    .
    Do please read and act on http://www.statalist.org/forums/help#stata

    Comment


    • #3
      I will look into and use dataex in my future posts. Thank you Nick this has been very helpfull.

      Comment

      Working...
      X