Announcement

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

  • Problem with ttesti: 'Est_A' found where number expected

    Hi,
    For the below data sample, my point estimates of interest are shown in Est_A and Est_B. Also, corresponding standard errors are se_A and se_B. I am trying to use the independent t-test (ttesti) to compare the point estimates for each pair of profile_new and quantity. I tried the code below but got an error: 'Est_A' found where number expected.

    ttesti 1000 Est_A se_A 1000 Est_B se_B, level(95)
    Thanks,
    NM


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 profile_new str5 quanitity float(Est_A se_A Est_B se_B)
    "0.W" "T" 31.517185   .1829556 31.157734   .1819736
    "1.B" "T"  28.81505   .3884638  28.58561   .4067602
    "2.H" "T" 32.466324   .6987514  32.71963   .6714985
    "0.W" "H"  23.64789  .17877084 23.408606  .19303873
    "1.B" "H"  18.13428  .33849216 17.833073   .3517772
    "2.H" "H" 19.285946   .6132159  19.38368   .6201337
    "0.W" "U"  7.869298  .10677572   7.74913  .11566485
    "1.B" "U"  10.68077  .23934667 10.752533   .2633325
    "2.H" "U" 13.180377   .4501724  13.33595   .4924842
    "0.W" "P"  .7503153 .003215158  .7512898 .003675577
    "1.B" "P"  .6293228 .007220326  .6238397 .007902899
    "2.H" "P" .59399104  .01214507  .5923899 .013387448
    end

  • #2
    ttesti is telling you the problem: it expects to see numbers (and so in particular not variable names). You don't show your code but for what you want you will need to loop over observations. And you'll need to convert your standard errors to standard deviations first.

    Here is a sketch:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 profile_new str5 quanitity float(Est_A se_A Est_B se_B)
    "0.W" "T" 31.517185   .1829556 31.157734   .1819736
    "1.B" "T"  28.81505   .3884638  28.58561   .4067602
    "2.H" "T" 32.466324   .6987514  32.71963   .6714985
    "0.W" "H"  23.64789  .17877084 23.408606  .19303873
    "1.B" "H"  18.13428  .33849216 17.833073   .3517772
    "2.H" "H" 19.285946   .6132159  19.38368   .6201337
    "0.W" "U"  7.869298  .10677572   7.74913  .11566485
    "1.B" "U"  10.68077  .23934667 10.752533   .2633325
    "2.H" "U" 13.180377   .4501724  13.33595   .4924842
    "0.W" "P"  .7503153 .003215158  .7512898 .003675577
    "1.B" "P"  .6293228 .007220326  .6238397 .007902899
    "2.H" "P" .59399104  .01214507  .5923899 .013387448
    end
    
    gen t = . 
    gen double Pvalue =. 
    
    local N = _N 
    
    forval i = 1/`N' { 
        ttesti 1000 `=Est_A[`i']' `=se_A[`i']*sqrt(1000)'  1000 `=Est_B[`i']' `=se_B[`i']*sqrt(1000)'
        replace t = r(t) in `i'
        replace Pvalue = r(p) in `i'
    }
    
    rename quanitity quantity 
    
    gen difference = Est_A - Est_B 
    sort difference 
    format t P difference %4.3f 
    char Pvalue[varname] "P-value"
    char profile[varname] "profile"
    
    list profile quantity diff t P, sep(0) abbrev(10) subvarname noobs 
    
      +----------------------------------------------------+
      | profile   quantity   difference        t   P-value |
      |----------------------------------------------------|
      |     2.H          T       -0.253   -0.261     0.794 |
      |     2.H          U       -0.156   -0.233     0.816 |
      |     2.H          H       -0.098   -0.112     0.911 |
      |     1.B          U       -0.072   -0.202     0.840 |
      |     0.W          P       -0.001   -0.200     0.842 |
      |     2.H          P        0.002    0.089     0.929 |
      |     1.B          P        0.005    0.512     0.609 |
      |     0.W          U        0.120    0.763     0.445 |
      |     1.B          T        0.229    0.408     0.683 |
      |     0.W          H        0.239    0.909     0.363 |
      |     1.B          H        0.301    0.617     0.537 |
      |     0.W          T        0.359    1.393     0.164 |
      +----------------------------------------------------+

    Comment

    Working...
    X