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

  • Geometric coefficient of variation

    dear Stata team,
    I was trying to search how to get the geometric coefficient of variation using STATA, as I was searching I found different equations and I wasn't sure if STATA has a code for the GCV or if there is a way to do it

    thank you very much

  • #2
    As a frequent user of the CV but who is not familiar with the "geometric CV," I had to search out its formula, two versions of which are given in the Wikipedia entry for the coefficient of variation
    One version is:
    CV_ln= sqrt[exp(s2ln) -1], where s2ln is the variance of the ln of the variable of interest. So, presuming you have a variable Y in your data set, you can use the following:

    gen lnY = ln(Y)
    summarize lnY
    scalar CV_ln = sqrt(exp(r(Var)) - 1)
    display "Geometric CV = " CV_ln
    If you want to use some other expression for the geometric CV, modify this appropriately.
    Last edited by Mike Lacy; 27 Feb 2018, 09:37.


    • #3
      Oddly, variables for which logarithmic transformations make sense (e.g. those loosely like the lognormal or gamma) often seem to be those for which the coefficient of variation makes sense too, so (very much like Mike, perhaps) this beast hadn't really registered with me.


      • #4
        Thank you Mike and Nick, I will apply this code and see how the results will be. It seems that the GCV is not a ratio as the CV is

        best regards


        • #5
          So I tried the codes and I also used a step by step codes just to compare but I got different results and I was wondering if I did something wrong
          This is based on the codes that is listed above:

           quietly gen ln`v'=ln(`v')
                                quietly summarize ln`v'
                               local gcv3= sqrt((exp(r(Var))) - 1)
                               local gcv2=`gcv3'*100
                                                    disp "`v'" _col(20) %4.3f `gcv2'
          then I tried these codes and I was assuming it should give me the same results:

           foreach v of varlist `varlist' {
                                  quietly gen log`v'=log(`v')
                                   quietly summarize log`v'
                                   local lvar=r(Var)
                                   local exp=exp(`lvar')
                                   local exp1=(`exp')-1
                                   local sqrt=sqrt(`exp1')
                                  local gcv2=`exp1'*100
                                                    disp "`v'" _col(20) %4.3f `gcv2'
          this is based on the equation in wikipedia and also knowing the default log in STATA is the ln

          do you have thoughts why it is giving different results?

          thank you very much
          Last edited by Umama Afr; 28 Feb 2018, 15:40.


          • #6
            oh Ok I figured that out it is the line before the last one in my codes! now they match!

            thank you very much