Announcement

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

  • Issue producing geometric means and standard deviation with svy commands in Stata 15

    I am working on a project using Stata 15.1 using survey data with a complex design, that also involves analyzing biochemical data.

    I tried to use this commands to get geometric mean and sd, but they are not working.

    svy: mean <variable>, over(variable2)
    ereturn display, eform (geo_mean).

    The "ereturn display" command simply returns the same value I get with the original svy command. I cannot find any information.
    Any assistance anyone could offer would be really appreciated.

    Thanks,
    Sara

  • #2
    You need to first log-transform the variable whose geometric mean you want to take, take the mean of that, and then use -nlcom- to exponentiate the result. You don't provide example data, so here is how it is done using one of the built-in Stata data sets:

    Code:
    webuse nhanes2b, clear
    
    gen log_height = log(height)
    svy: mean log_height, over(sex) coeflegend
    
    foreach x in Male Female {
        display _newline(3) `"`x'"'
        nlcom exp(_b[log_height:`x'])
    }
    In the future, when asking for coding help, always provide example data. And use the -dataex- command to do that. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



    When asking for help with code, always show example data. When showing example data, always use -dataex-.


    Comment

    Working...
    X