Announcement

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

  • Creating a Panel and Column names

    Hi,

    How could get the first row first Column: Germany to become a panel (so to match each observation. And then to name each column by their second row? So column names should be, year, Pproducer price index for industrial products and annual change.



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str78 A str44 B str13 C
    "Germany"                                                                        ""                                             ""             
    "Year"                                                                           "Producer price index for industrial products" "Annual change"
    ""                                                                               "2015=100"                                     "in (%)"       
    "2007"                                                                           "93.8"                                         "1.3"          
    "2008"                                                                           "99"                                           "5.5"          
    "2009"                                                                           "94.8"                                         "-4.2"         
    "2010"                                                                           "96.2"                                         "1.5"          
    "2011"                                                                           "101.3"                                        "5.3"          
    "2012"                                                                           "103"                                          "1.7"          
    "2013"                                                                           "102.9"                                        "-.1"          
    "2014"                                                                           "101.9"                                        "-1"           
    "2015"                                                                           "100"                                          "-1.9"         
    "2016"                                                                           "98.40000000000001"                            "-1.6"         
    "2017"                                                                           "101.1"                                        "2.7"          
    "______________"                                                                 ""                                             ""             
    ""                                                                               ""                                             ""             
    end

  • #2
    This works for your example.

    Code:
    foreach v in A B C { 
          label var `v' `"`=`v'[2] + " " + `v'[3]'"' 
    } 
    
    drop if missing(real(A)) 
    label data "Germany" 
    destring, replace 
    
    list 
    
         +---------------------+
         |    A       B      C |
         |---------------------|
      1. | 2007    93.8    1.3 |
      2. | 2008      99    5.5 |
      3. | 2009    94.8   -4.2 |
      4. | 2010    96.2    1.5 |
      5. | 2011   101.3    5.3 |
         |---------------------|
      6. | 2012     103    1.7 |
      7. | 2013   102.9    -.1 |
      8. | 2014   101.9     -1 |
      9. | 2015     100   -1.9 |
     10. | 2016    98.4   -1.6 |
         |---------------------|
     11. | 2017   101.1    2.7 |
         +---------------------+
    
    describe 
    
    Contains data
      obs:            11                          Germany
     vars:             3                          
     size:           198                          
    --------------------------------------------------------------------------------------------------------------------------------------------------
                  storage   display    value
    variable name   type    format     label      variable label
    --------------------------------------------------------------------------------------------------------------------------------------------------
    A               int     %10.0g                Year
    B               double  %10.0g                Producer price index for industrial products 2015=100
    C               double  %10.0g                Annual change in (%)
    --------------------------------------------------------------------------------------------------------------------------------------------------
    Sorted by: 
         Note: Dataset has changed since last saved.
    If you have other countries too, you need to tell us more about your data.

    Comment


    • #3
      Hey Nick, thank you.

      I think I may have explained myself poorly. I want Germany to be in the first column, in years 2007 - 2015 so that later I can match it with a bigger dataset.

      Is that possible?

      Comment


      • #4
        You can just go

        Code:
        gen country = "Germany"



        Comment

        Working...
        X