Announcement

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

  • Mean Comparison Test

    Dear all,

    I am trying to perform a mean comparison test for two subgroups of my dataset. I have split up the dataset in Group1 and Group2 ( by median value of Variable a)

    Now I need the code ( ideally in a foreach command) to perform a mean comparison tests for the Group 1 and Group 2 means of my variables b,c,d,e,f,g
    Is this test possible within my main dataset or do I need to create two separate datasets ( one only including the observations >mean of Variable a : and the other one only < mean of Variable a)?

    Advice much appreciated ! Thank you !

  • #2
    Linda:
    you may want to try something along the following lines:
    Code:
    sysuse auto.dta
    foreach var of varlist price-headroom {
    ttest `var', by(foreign) unequal
      }
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Here's a twist on Carlo's helpful coded example. As well as firing a shotgun with all those tests, why not also compile a portfolio of relevant graphs? The ideal conditions here remain normal distributions with distinct means. We can check for distinct means, the same or different SDs and deviations from normality by firing up a normal quantile plot each time around the loop. Here I use qplot (SJ), which must be installed first.

      Code:
      sysuse auto.dta
      local G
      local g = 1
      foreach var of varlist price mpg weight length {
          ttest `var', by(foreign) unequal
          qplot `var', over(foreign) trscale(invnormal(@)) ///
          xtitle(standard normal deviate) name(G`g') legend(pos(11) ring(0) col(1))
          local G `G' G`g'
          local ++g
      }
      
      graph combine `G'
      Click image for larger version

Name:	qplottimes4.png
Views:	1
Size:	26.0 KB
ID:	1396037



      Just a variation on http://www.statalist.org/forums/foru...sample-t-tests What's often apparent in such graphs is a signal that we working on the wrong scale. As Carlo Lazzaro 's compatriot Galileo Galilei pointed out 400 years ago, it should be log price that is the focus.
      Last edited by Nick Cox; 02 Jun 2017, 09:22.

      Comment


      • #4
        Nick is obviously right.
        Interestingly, Galileo Galilei is usually more studied in philosophy than in maths/physisc classes in Italian high-schools.
        This may support the evidence that Italians are, in general more qualitative than quantitative (and our high public debt is probably a case in point!).
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X