Announcement

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

  • Generate variables contain summary statistics

    Hi

    I want to covert the summary statistic table generated by command "sum var1-var10" into variables (i.e create a column variable contain the mean for var1 to var10)
    All helps appreciated
    Cheers
    Tom

  • #2
    Please take a look into the help file of the egen command, the egen mean_a=mean(x) is what you are looking for. Alternatively, you might also find the collapse command helpful.

    Comment


    • #3
      Thanks for the reply, I have tried egen mean_a=mean(var1) &egen mean_a=mean(var1-var10) is not exactly what Im looking for, I want a column of variable that contain the mean for all 10 variables thus the values in that column should start with mean(var1) in first row, mean(var2) in second row,....mean(var10) in 10th row.

      Comment


      • #4
        not at all sure why you want it but the following, inelegant, code should do it (untested):
        Code:
        gen varmeans=.
        forval i=1/10 {
        qui su var`i', meanonly
        replace varmeans=r(mean) if _n==`i'

        Comment


        • #5
          Following up on Oded's recommendation of the collapse command, perhaps the following example will lead to a solution that meets your needs.
          Code:
          . sysuse auto
          (1978 Automobile Data)
          
          . collapse price mpg weight
          
          . list
          
               +-----------------------------+
               |   price       mpg    weight |
               |-----------------------------|
            1. | 6,165.3   21.2973   3,019.5 |
               +-----------------------------+
          
          . xpose, clear varname
          
          . list
          
               +---------------------+
               |       v1   _varname |
               |---------------------|
            1. | 6165.257      price |
            2. |  21.2973        mpg |
            3. | 3019.459     weight |
               +---------------------+
          
          .
          Last edited by William Lisowski; 28 Jul 2015, 18:49.

          Comment


          • #6
            Thanks Rich and William, problem solved!!

            Comment

            Working...
            X