Announcement

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

  • Mean of a variable by multiple variables in the same table

    Hi.

    In my data there are 20 variables (var1- var20) which are deciles created based on different factors. So all variables var1 to var20 take values from 1 to 10.

    I want to calculate the mean of another variable (let's call it height ) for each decile for each of the variables var1 to var20.

    So in total i am looking at 20* 10 = 200 mean values of height. Want to create a large table with columns var1 to var20 and the means below.

    How can one do it in STATA!

    Thanks.

  • #2
    I think you need a different structure for your data to do this, at least temporarily.

    Absent a data example, most of this code is about creating one. See https://www.statalist.org/forums/help#stata and in passing https://www.statalist.org/forums/help#spelling


    Code:
    * example data 
    clear
    set obs 100 
    set seed 2803 
    forval j = 1/20 { 
        gen var`j' = runiformint(1, 10)
        
    }
    
    gen height = exp(rnormal(0,1))
    gen id = _n 
    
    * some technique 
    reshape long var, i(id) j(which) 
    rename var decile
    table decile which, c(mean height)

    Comment


    • #3
      Hi

      Could someone please tell me how to export this table created using the command table to an Excel file.

      Comment

      Working...
      X