Announcement

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

  • Paired t-test by groups

    Hi everyone, I'm trying to run a paired t-test Using only one variable, but two groups.For example, I'm specifically looking at whether marital status changed (Logically it would not have) pre and post the implementation of the ACA using survey data.


    I know that paired t-tests are run using:
    ttest pre==post

    and I know that t-tests using groups would be run using:
    ttest marital, by (ACA)

    However, it seems that the second line of code is a two-sample t-test and not a paired one. Even using the GUI, there doesn't seem to be a way to run a paired t-test using groups as the "pre and post" category.

    I attached a screenshot of my output when I use the grouping command, which is not paired.

    Thanks!

    Click image for larger version

Name:	Screen Shot 2017-08-13 at 12.39.06.png
Views:	1
Size:	19.8 KB
ID:	1406170


  • #2
    You are correct that what you are getting here is an unpaired t-test.

    In order to get a paired t-test out of this, you need some kind of id variable that links the pre-ACA and post-ACA observations on the same variable. Let's just call it id. Then you can do the following:

    Code:
    xtset id
    xtreg marital i.ACA
    The results table's line for ACA will give you the mean paired difference in marital status, along with a t-test which is identical to what a paired t-test would give you.

    Alternatively, but I think more complicated, you can reshape your data into wide layout with a marital_pre_ACA and a marital_post_ACA variable and one observation per id. Then you can use the ttest marital_pre_ACA = marital_post_ACA approach. In addition to being harder than the approach using -xtreg, fe-, you will be left with a data set in wide layout and, if you are planning further analysis, you will likely have to then -reshape- it back to long layout for your other commands.

    Comment


    • #3
      I actually misspoke: I don't actually have one ACA variable, i have two separate variables, "expansion" and "nonexpansion", where expansion is pre-ACA and nonexpansion the post-ACA.

      In that case, how would that change things? My output actually is the attached image. Is there a way to do it without creating the ACA variable?



      Click image for larger version

Name:	Screen Shot 2017-08-13 at 13.43.56.png
Views:	1
Size:	36.7 KB
ID:	1406179

      Comment


      • #4
        So, having an expansion variable and a non-expansion variable is an inefficient data design. Each of those variables is completely redundant of the other, so having two of them is a waste of space And you can see that in your output: the 0 row of the first t-test is identical to the 1 row of the other and vice versa, and the final t-test results are also identical. So get rid of one of those variables: it doesn't matter which. Let's say, for the sake of illustration you keep only the expansion variable.

        Then it's
        Code:
        xtset id
        xtreg marital i.expansion, fe
        That will give you a paired t-test.

        As an aside, please read FAQ #12 for good advice on the best ways to show code and output. As it happens, the screenshots you have shown are readable, but often they turn out not to be. Also, if you show code that way and somebody wants to try out your code, you leave them no choice but to re-type it by hand, as you cannot copy/paste from an image. So please avoid screenshots altogether on this forum, unless it is a screenshot of a graph, or you are showing an image taken from an article or something like that. While you are reading FAQ #12, pay attention also to the -dataex- command. So far, your questions have not required an example of your data. But it is likely that future questions will. -dataex- is the most helpful way to show example data. So it's in your interest to learn to use it now.



        Comment

        Working...
        X