Announcement

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

  • Perform a paired ttest on two substracts of the same variable

    I have a dataset that looks like this:
    var1 var2 var3 attribute
    1 0.93 0.88 1
    1 0.76 0.20 1
    1 0.40 0.18 0
    0 0.34 0.91 1
    0 0.09 0.51 0
    ... ... ... ...
    For each variable (var1, var2, var3, etc), I need to perfom a ttest compairing its mean when attribute = 1 vs the mean of the whole variable. How can I do this?

  • #2
    A couple points. The title says (bold is by me):

    Perform a paired ttest on two substracts of the same variable
    and then in the text, it says:

    I need to perfom a ttest compairing its mean when attribute = 1 vs the mean of the whole variable. How can I do this?
    I don't understand how this can be done in a paired t-test. Let's say var3 and var3|attribute == 1 is like the followings. The paired t-test result will be zero:

    Code:
    clear
    input v1 v2 v3 attribute
    1 0.93 0.88 1
    1 0.76 0.20 1
    1 0.40 0.18 0
    0 0.34 0.91 1
    0 0.09 0.51 0
    end
    
    keep v3 attribute
    gen v3b = v3 if attribute == 1
    list
    ttest v3 == v3b
    Results:

    Code:
    . list
    
         +----------------------+
         |  v3   attrib~e   v3b |
         |----------------------|
      1. | .88          1   .88 |
      2. |  .2          1    .2 |
      3. | .18          0     . |
      4. | .91          1   .91 |
      5. | .51          0     . |
         +----------------------+
    
    . ttest v3 == v3b
    
    Paired t test
    ------------------------------------------------------------------------------
    Variable |     Obs        Mean    Std. err.   Std. dev.   [95% conf. interval]
    ---------+--------------------------------------------------------------------
          v3 |       3    .6633333    .2318285    .4015387   -.3341441    1.660811
         v3b |       3    .6633333    .2318285    .4015387   -.3341441    1.660811
    ---------+--------------------------------------------------------------------
        diff |       3           0           0           0           0           0
    ------------------------------------------------------------------------------
         mean(diff) = mean(v3 - v3b)                                  t =        .
     H0: mean(diff) = 0                              Degrees of freedom =        2
    
     Ha: mean(diff) < 0           Ha: mean(diff) != 0           Ha: mean(diff) > 0
     Pr(T < t) =      .         Pr(|T| > |t|) =      .          Pr(T > t) =      .
    Did you mean independent sample t-test?

    Also, please take some time to read the FAQ (http://www.statalist.org/forums/help). Pay attention to section 12 on using command dataex to provide Stata-readable data code. Like this:


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(v1 v2 v3 attribute)
    1 .93 .88 1
    1 .76  .2 1
    1  .4 .18 0
    0 .34 .91 1
    0 .09 .51 0
    end

    Comment


    • #3
      Code:
      clear
      input v1 v2 v3 attribute
      1 0.93 0.88 1
      1 0.76 0.20 1
      1 0.40 0.18 0
      0 0.34 0.91 1
      0 0.09 0.51 0
      end
      The only t test that I can imagine here with a clear rationale compares each other variable by attribute. I agree with Ken Chui that this kind of test isn't paired.


      Code:
      forval j = 1/3 {
          ttest v`j', by(attribute)
      }
      Cross-posted at https://stackoverflow.com/questions/...-same-variable

      Please note our cross-posting policy, which is that you are asked to tell us about it. https://www.statalist.org/forums/help#crossposting
      Last edited by Nick Cox; 30 Nov 2022, 18:46.

      Comment

      Working...
      X