Announcement

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

  • dividing each column by the first value

    Dear Profs and colleagues,

    I am going to divide each column by the first value of that column which is the value for the year 2010. The result should be one in the year 2010.

    e.g
    Value_10:
    11525.832/ 11525.832=1
    12170.209 / 11525.832=
    12314.61 / 11525.832=
    12585.174/ 11525.832=

    Value_11:
    2769.224 / 2769.224=1
    2681.582 / 2769.224=
    .
    .

    .
    Code:
    clear
    input int Year double(Value_10 Value_11)
              2010        11525.832  2769.224
              2011        12170.209  2681.582
              2012        12314.61   2716.226
              2013        12585.174  2758.651
              2014        12446.254  2928.394
    end
    I started by this code:
    Code:
    sort Year
    foreach sfx in 10 11 {
        generate Def_`sfx' =Value_`sfx'/_n
    }
    Could anyone help me to complete it? Thanks

    Cheers,
    Paris


  • #2
    Code:
     
      generate Def_`sfx' = Value_`sfx'/Value_`sfx'[1]
    For column read variable.

    Comment


    • #3
      You can subscript using generate.

      Code:
      sort year
      forval v=10/11{
          gen wanted`v'= Value_`v'/ Value_`v'[1]
      }

      Comment


      • #4
        Thank you so much, dear Nick & Andrew.
        its perfect.

        Comment


        • #5
          See also https://www.stata-journal.com/articl...article=dm0055 for various related tips and tricks.

          Comment

          Working...
          X