Statistics Made Easy

## How to Perform a Two Sample t-test in Stata

A two sample t-test is used to test whether or not the means of two populations are equal.

This tutorial explains how to conduct a two sample t-test in Stata.

## Example: Two Sample t-test in Stata

Researchers want to know if a new fuel treatment leads to a change in the average mpg of a certain car. To test this, they conduct an experiment in which 12 cars receive the new fuel treatment and 12 cars do not.

Perform the following steps to conduct a two sample t-test to determine if there is a difference in average mpg between these two groups.

Step 1: Load the data.

First, load the data by typing use http://www.stata-press.com/data/r13/fuel3 in the command box and clicking Enter.

Step 2: View the raw data.

Before we perform a two sample t-test, let’s first view the raw data. Along the top menu bar, go to Data > Data Editor > Data Editor (Browse) . The first column, mpg , shows the mpg for a given car. The second column, treated , indicates whether or not the car received the fuel treatment (0 = no, 1 = yes).

Step 3: Visualize the data.

Next, let’s visualize the data. We’ll create boxplots to view the distribution of mpg values for each group.

Along the top menu bar, go to Graphics > Box plot . Under variables, choose mpg :

Then, in the Categories subheading under Grouping variable, choose treated :

Click OK . A chart with two boxplots will automatically be displayed:

Right away we can see that the mpg appears to be higher for the treated group (1) compared to the non-treated group (0), but we need to conduct a two-sample t-test to see if these differences are statistically significant.

Step 4: Perform a two sample t-test.

Along the top menu bar, go to Statistics > Summaries, tables, and tests > Classical tests of hypotheses > t test (mean-comparison test) .

Choose Two-sample using groups . For Variable name, choose mpg . For Group variable name, choose treated . For Confidence level, choose any level you’d like. A value of 95 corresponds to a significance level of 0.05. We will leave this at 95. Lastly, click OK .

The results of the two sample t-test will be displayed:

We are given the following information for each group:

Obs: The number of observations. There are 12 observations in each group.

Mean: The mean mpg. In group 0, the mean is 21. In group 1, the mean is 22.75.

Std. Err: The standard error, calculated as σ / √ n

Std. Dev: The standard deviation of mpg.

95% Conf. Interval: The 95% confidence interval for the true population mean of mpg.

t: The test statistic of the two-sample t-test.

degrees of freedom: The degrees of freedom to be used for the test, calculated as n-2 = 24-2 = 22.

The p-values for three different two sample t-tests are displayed at the bottom of the results. Since we are interested in understanding if the average mpg is simply different between the two groups, we will look at the results of the middle test (in which the alternative hypothesis is Ha: diff !=0) which has a p-value of 0.1673 .

Since this value is not smaller than our significance level of 0.05, we fail to reject the null hypothesis. We do not have sufficient evidence to say that the true mean mpg is different between the two groups.

Step 5: Report the results.

Lastly, we will report the results of our two sample t-test. Here is an example of how to do so:

A two sample t-test was conducted on 24 cars to determine if a new fuel treatment lead to a difference in mean miles per gallon. Each group contained 12 cars. Results showed that the mean mpg was not different between the two groups (t = -1.428 w/ df=22, p = .1673) at a significance level of 0.05. A 95% confidence interval for the true difference in population means resulted in the interval of (-4.29, .79).

## Featured Posts

Hey there. My name is Zach Bobbitt. I have a Masters of Science degree in Applied Statistics and I’ve worked on machine learning algorithms for professional businesses in both healthcare and retail. I’m passionate about statistics, machine learning, and data visualization and I created Statology to be a resource for both students and teachers alike. My goal with this site is to help you learn statistics through using simple terms, plenty of real-world examples, and helpful illustrations.

## One Reply to “How to Perform a Two Sample t-test in Stata”

i did similar test on stata. but my aim was to show the group 0 is significantly smaller than group 1 in terms of mean. so my p value results

Ha: diff 0 Pr(T |t|) = 0.0895 Pr(T > t) = 0.9553 so this results support my assumption? or the p value (which is in the middle) greater than 0,05 and i can not say there is a difference significantly.

## Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

## Join the Statology Community

Sign up to receive Statology's exclusive study resource: 100 practice problems with step-by-step solutions. Plus, get our latest insights, tutorials, and data analysis tips straight to your inbox!

By subscribing you accept Statology's Privacy Policy.

## An overview of multiple hypothesis testing commands in Stata

David mckenzie.

Updated September 14, 2020 to reflect that my initial post using an older version of rwolf, and that a new version of wyoung that allows for multiple treatments has been released. And updated again April 16, 2021 to reflect a new update to wyoung which allows for more easily including different controls in each equation.

There are a growing number of user-written Stata packages for conducting multiple hypothesis testing. I thought I would compare the pros and cons of several of these, both as a way of helping remind myself of which packages work for which settings, as well as to potentially help others. I start by acknowledging gratitude to the authors of these various packages for writing this code at all, so even when I complain that it doesn’t do everything I need in particular applications, it may be very useful for other needs.

What is the problem we are trying to solve?

Suppose we have run an experiment with four treatments ( treat1, treat2, treat3, treat4) , and are interested in examining impacts on a range of outcomes ( y1, y2, y3, y4, y5). We run the following treatment regressions for outcome j at time t:

Y(j,t) = a + b1*treat1+b2*treat2+b3*treat3+b4*treat4 + c1*y(j,0) + d’X + e(j,t)

With 5 outcomes and 4 treatments, we have 20 hypothesis tests and thus 20 p-values. Here’s an example from a recent experiment of mine (where the outcomes are firm survival, and four types of business practice measures) and the treatments are different ways of helping firms learn new practices – where the p-values are shown under the coefficients.

Suppose that none of the treatments have any effect on any outcome (all null hypotheses are true), and that the outcomes are independent. Then if we just test the hypotheses one by one, then the probability that of one or more false rejections when using a critical value of 0.05 is 1-0.95^20 = 64% (and using a critical value of 0.10 is 88%. As a result, in order to reduce the likelihood of these false rejections, we want some way of adjusting for the fact that we are testing multiple hypotheses. That is what these different methods do.

Anderson’s code for FDR sharpened q-values

One of the most popular ways to deal with this issue is to use Michael Anderson’s code to compute sharpened False Discovery Rate (FDR) q-values. The FDR is the expected proportion of rejections that are type I errors (false rejections). Anderson discusses this procedure here .

This code is very easy to use. You need to just save the p-values and then read them as data into Stata, and run his code to get the sharpened q-values. For my little example, they are shown in the table below.

A few points to note:

· A key reason for the popularity of this approach (in addition to its simplicity) is seen in the comparison of the original p-values to sharpened q-values. If we were to apply a Bonferroni adjustment, we would multiply the p-values by the number of outcomes (20) and then cap at 1.000. Then, for example, the p-value of 0.031 for outcome Y3 and treatment 1 would be adjusted to 0.62. Instead the sharpened q-value is 0.091. That is, this approach has a lot greater power than many other methods.

· Because this takes the p-values as inputs, you have a lot of flexibility into what goes into each treatment regression: for example, you can have some regressions with clustered errors and some without, some with controls and some without, etc.

· As Anderson notes in his code, sharpened q-values can actually be LESS than unadjusted p-values in some cases when many hypotheses are rejected, because if there are many true rejections, you can tolerate several false rejections too and still maintain the false discovery rate low. We see an example of this for outcome Y1 and treatment 1 here.

· A drawback of this method is that it does not account for any correlations among the p-values. For example, in my application, if a treatment improves business practices Y2, then we might think it is likely to have improved business practices Y3, Y4, and Y5. Anderson notes that in simulations the method seems to also work well with positively dependent p-values, but if the p-values have negative correlations, a more conservative approach is needed.

This code implements a procedure set out by John List, Azeem Shaikh and Yang Xu (2016) , and can be obtained by typing ssc install mhtexp

This procedure aims to control the familywise error rate (FWER), which is the probability of making any type I error. It builds on work by Romano and Wolf, and uses a bootstrapping approach to incorporate information about the joint dependence structure of the different tests – that is, it allows for the p-values to be correlated.

· This command allows for multiple outcomes and multiple treatments, but does not allow for the inclusion of control variables (so no controlling for baseline values of the outcome of interest, or for randomization strata fixed effects), and does not allow for clustering of standard errors.

· The command is then straightforward. Here I have created a variable treatgroup which takes value 0 for the control group, 1 for treat 1, 2 for treat 2, 3 for treat 3, and 4 for treat 4. Then the command is:

mhtexp y1 y2 y3 y4 y5, treatment(treatgroup) bootstrap(3000)

I’ve added these FWER p-values to the table below. While not as large as Bonferroni p-values would be, you can see they are much larger that the original p-values and sharpened q-values. Not much of this is due to not including the control variables in this particular case, since the raw p-values don’t change that much with the addition of the controls. Instead, this reflects the issue of using FWER with many comparisons – in order to avoid making any type I error, the adjustments become increasingly severe as you add more and more outcomes or treatments. That is, power becomes low. In contrast, the FDR approach is willing to accept some type I error in exchange for more power. Which is more suitable depends on how costly false rejections are versus power to examine particular effects.

Note my original post used an earlier version of this command which allowed only a single treatment. The command now allows for multiple treatments.

This command calculates Romano-Wolf stepdown adjusted p-values, which control the FWER and allows for dependence among p-values by bootstrap resampling. It is therefore aiming to do the same things as mhtexp , although with a slightly different algorithm, and was developed by Romano and Wolf themselves (along with Damien Clarke), and is described here . To get this type ssc install rwolf

· In contrast to mhtexp, this command does allow for you to include control variables in the regression, but does force them to be the same for every outcome. It also has an option to include the baseline value of the outcome, so you can allow this to differ across outcomes and do Ancova (so long as you don't have missing baseline values and need a separate dummy for a missing baseline).

· It also allows for clustered randomization, and can do the bootstrap re-sampling by taking account of both randomization strata and of clustered assignment.

An earlier version of the command only allowed for a single treatment, but now the command allows for multiple treatments. However, it currently only runs the multiple testing correction for each treatment at a time. That is, it will correct for testing treat1 on 5 outcomes, but not for the fact that you are also testing other treatments at the same time. As such, I currently do not recommend its use for multiple treatment corrections. This will get addressed in a future update, and I will aim to revise this post then.

· To illustrate for a single treatment, I will just keep treatment 1 and the control, and then also compare the other methods above when applied just to this set of 5 comparisons (treatment 1 effects on each of the five outcomes). Then the command is:

rwolf y1 y2 y3 y4 y5 if treatment<=1, indepvar(treat1) controls(i.strata) reps(1000)

You can see the rwolf p-values are pretty similar to those from mhtexp as expected.

With multiple treatments, you can use code like: rwolf y1 y2 y3 y4 y5, indepvar(treat1 treat2 treat3 treat4) reps(1000) method(areg) abs(batchno) bl(_bl) strata(batchno) seed(456) r - but see note above, I do not recommend using the command for multiple treatment corrections at the moment, since it only adjusts within a treatment, and not across treatments.

The command also now allows you to use commands like areg, ivreg, etc. so long as you are using the same method for all regressions.

This command, programmed by Julian Reif, calculates Westfall-Young stepdown adjusted p-values, which also control the FWER and allow for dependence amongst p-values. This method is a precursor to the Romano-Wolf procedure, using bootstrap resampling to allow for dependence across outcomes. Romano and Wolf note that the Westfall-Young procedure requires an additional assumption of subset pivotality, which can be violated in certain settings, and so the Romano-Wolf procedure is more general. I don’t have a great sense of when it breaks down.

To get this command, type ssc install wyoung

Update April 2021: use the command below instead

net install wyoung, from(" https://raw.githubusercontent.com/reifjulian/wyoung/controls-option ") replace

· A nice feature of this command is that it allows you to have different control variables in different equations. So you can control for the baseline variable of each outcome, for example. It also allows for clustered randomization and can do bootstrap re-sampling that accounts for both randomization strata and clustered assignment.

· When I first blogged about these commands, it it only allowed for a single treatment variable.

Like the Romano-Wolf example above, I therefore look at this adjustment on the five outcomes for treatment 1, and compare to the other methods. The command is a bit longer looking, because it allows for different regressions – note I have no baseline outcome for y1 (survival) since all firms were alive to begin with, and then control for the baselines levels of the other outcomes b_y1, etc.

wyoung, cmd("areg y1 treat1, r a(strata)" "areg y2 treat1 b_y2, r a(strata)" "areg y3 treat1 b_y3, r a(strata)" "areg y4 treat1 b_y4, r a(strata)" "areg y5 treat1 b_y5, r a(strata)" familyp(treat1) bootstraps(1000) seed(124)

This gives pretty similar adjusted values as mhtexp and rwolf , which is to be expected since they are all trying to control the FWER using similar approaches.

After the update, the command now allows for multiple treatments. When you have the same controls across all regressions, the command is quite simple:

wyoung y1 y2 y3 y4 y5, cmd(areg OUTCOMEVAR treat1 treat2 treat3 treat4, r a(strata)) familyp(treat1 treat2 treat3 treat4) bootstraps(1000) seed(123)

If you have different controls in each equation, then the command is a lot more clunky - you have to list each equation the number of times it is being tested, and each variable for each equation. e.g.

wyoung, cmd("areg y1 treat treat2 treat3 treat, r a(batchno)" "areg y2 treat1 treat2 treat3 treat4 basey2, r a(batchno)" "areg y3 treat1 treat2 treat3 treat4 basey3, r a(batchno)" "y4 treat1 treat2 treat3 treat4 basey4, r a(batchno)" "y5 treat1 treat2 treat3 treat4 basey5, r a(batchno)" "areg y1 treat treat2 treat3 treat, r a(batchno)" "areg y2 treat1 treat2 treat3 treat4 basey2, r a(batchno)" "areg y3 treat1 treat2 treat3 treat4 basey3, r a(batchno)" "y4 treat1 treat2 treat3 treat4 basey4, r a(batchno)" "y5 treat1 treat2 treat3 treat4 basey5, r a(batchno)" "areg y1 treat treat2 treat3 treat, r a(batchno)" "areg y2 treat1 treat2 treat3 treat4 basey2, r a(batchno)" "areg y3 treat1 treat2 treat3 treat4 basey3, r a(batchno)" "y4 treat1 treat2 treat3 treat4 basey4, r a(batchno)" "y5 treat1 treat2 treat3 treat4 basey5, r a(batchno)" "areg y1 treat treat2 treat3 treat, r a(batchno)" "areg y2 treat1 treat2 treat3 treat4 basey2, r a(batchno)" "areg y3 treat1 treat2 treat3 treat4 basey3, r a(batchno)" "y4 treat1 treat2 treat3 treat4 basey4, r a(batchno)" "y5 treat1 treat2 treat3 treat4 basey5, r a(batchno)") familyp(treat1 treat1 treat1 treat1 treat1 treat2 treat2 treat2 treat2 treat2 treat3 treat3 treat3 treat3 treat3 treat4treat4 treat4 treat4 treat4) bootstraps(1000) seed(124)

Update April 14, 2021: Julian has added a new option to make it much easier to include different controls in each equation, and the syntax is much simpler as a result:

wyoung Y1 Y2 Y3 Y4 Y5, cmd(areg OUTCOMEVAR treat1 treat2 treat3 treat4 CONTROLVARS, r a(strata)) familyp(treat1 treat2 treat3 treat4) controls("constant" "b_Y2" "b_Y3" "b_Y4" "b_Y5") bootstraps(1000) seed(123);

Note that since I did not want to include any controls for outcome Y1, I created a variable called constant which just has value one for everyone, and use that in the command.

This gives the adjusted FWER p-values in the table below, which differ from the mhtexp ones in using Westfall-Young rather than Romano-Wolf, and in controlling for baseline variables.

This is a Stata command written by Alwyn Young that calculates randomization inference p-values, based on his recent QJE paper . It is doing something different to the above approaches. Rather than adjusting each individual p-value for multiple testing, it conducts a joint test of the sharp hypothesis that no treatment has any effect, and then uses the Westfall-Young approach to test this across equations. So in my example, it tests that there is no effect of any treatment on outcome Y1 (p=0.403), Y2 (p=0.0.045) etc., and then also tests the null of complete irrelevance – that no treatment had no effect on any outcome (p=0.022 here). The command is very flexible in allowing for each equation to have different controls, different samples, having clustered standard errors, etc. But it is testing a different hypothesis than the other approaches above.

Addendum: mhtreg

Turns out others have also realized these limitations, and Andreas Steinmayr has extended the mhtexp command to allow for the inclusion of different controls in different regressions, and for clustered randomization, with a command mhtreg

To get this: type

ssc install mhtreg

I tried this out, and it does indeed allow for different controls in different regressions. It is definitely an improvement on mhtexp. A couple of limitations to be aware of:

· The syntax is a bit awkward with multiple treatments – it only does corrections for the first regressor in each equation, so if you want to test for multiple treatments, you have to repeat the regression and change the order in which treatments are listed. E.g. to test the 20 different outcomes in my example, the code is:

mhtreg (y1 treat1 treat2 treat3 treat4 i.strata, r) (y1 treat2 treat3 treat4 treat1 i.strata, r) (y1 treat3 treat4 treat1 treat2 i.strata, r) (y1 treat4 treat1 treat2 treat 3 treat4 i.strata, r)

(y2 treat1 treat2 treat3 treat4 b_y2 i.strata, r) (y2 treat2 treat3 treat4 treat1 b_y2 i.strata, r)….

· It requires each treatment regression to actually be a regression – that is, to have used the reg command, and not commands like areg or reghdfe; or for you to be doing ivreg or probits, or something else – so you will need to add any fixed effects as regressors, and better be doing ITT and not TOT or other non-regression estimation. This can be contrasted with the wyoung command.

An additional thing to watch out for (that likely applies to the other commands as well) is that, even with the default 3000 bootstrap replications, the corrected p-values can change a bit from one random seed to another. This seems particularly an issue for really low p-values, where you are looking at uncommon events. For example, for outcome Y4, treatment 1, using three different seeds and mhtreg, I get adjusted p-values of 0.0003, 0.0057, and 0.011. So you may need to specify a lot more replications to get robustness of these adjusted values to choice of seed.

Here is the table of my results using mhtreg and comparing to the mhtexp and sharpened q-values. You see the results are similar to mhtexp, the differences are coming from the inclusion of baseline controls.

Putting it altogether

The table below compares the multiple hypothesis testing command continues. With a small number of hypothesis tests, controlling the FWER is useful, and then wyoung now seems to be the one I will prefer. With lots of outcomes and treatments, controlling the FDR seems the best approach, and so the Anderson q-value approach is my stand-by. I only wish it would account for correlations between outcomes. The Young omnibus test of overall significance is a useful compliment, but answers a different question.

Note the updated version of rwolf does allow for multiple treatments (but only currently adjusts for testing multiple outcomes for a treatment, but not for multiple testing across treatments - so I do not recommend for multiple treatments), for different commands (areg, ivreg). You can include a different baseline variable in each regression, but otherwise need to have the controls be the same.

## Get updates from Development Impact

Thank you for choosing to be part of the Development Impact community!

Your subscription is now active. The latest blog posts and blog-related announcements will be delivered directly to your email inbox. You may unsubscribe at any time.

Lead Economist, Development Research Group, World Bank

## Join the Conversation

- Share on mail
- comments added

## Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

## Comparing the difference in means (group 1 v. group 2 and group 1 v. group 3)

I am a complete beginner in statistics. I have a database in Stata with data on people's cholesterol levels (continuous variable "cholesterol") and an indicator for whether the person is a vegetarian (binary variable "vegetarian"). Each person belongs to one of three groups (categorical variable "group", with possible values 1, 2 or 3). For each variable "cholesterol" and "vegetarian", I want to test:

Is the difference in mean/proportion between group 1 and group 2 equal to the difference in mean/proportion between group 1 and group 3?

Is the difference in mean/proportion between group 1 and group 2 greater than the difference in mean/proportion between group 1 and group 3?

I would like to know the appropriate two-sided and one-sided hypothesis test to use for difference in means/proportions when you have a continuous variable and a binary variable. If anyone has knowledge of Stata, I would also like to know how to run these tests.

Appreciate further guidance or advice for resources where I can read more on this!

- hypothesis-testing

- $\begingroup$ Shall we assume that you want to test both (and independently) cholesterol levels and vegetarian status across the three groups, i.e. each of the hypotheses (1) and (2) subsume two tests? $\endgroup$ – chl Commented Nov 29, 2020 at 19:31
- $\begingroup$ Yes, I was thinking there will be two independent tests for each (1) and (2). $\endgroup$ – Helen Miller Commented Nov 29, 2020 at 19:39

This is a common problem, so I will explain the general idea (otherwise this would be off-topic here), and then code it up in Stata. This assumes that you have a decent understanding of regression and hypothesis testing.

The basic idea is to take a two-sided test from a regression, which almost any software can do, and then manufacture a one-sided test out of that output. There are two ways of doing that. One is easy (divide the p-value by two), but doesn't always work (you need to flip the rules depending on the sign of the difference). The other is harder, but always works. There are also two variants of the hard one, depending on the type of two-sided test.

We will start by constructing a dataset of pig weights taken in weeks 1-3, 4-6, and 7-9. These will be our 3 groups. Pigs who are weighed in later weeks are on average heavier since they are older.

So we have 3 groups, with 48 pigs in total. Weight does seem to increase with group/age.

Now that we have the data, we can fit a regression:

The margins command calculates the expect weight in each group from the regression output: group 3 is more than twice as heavy on average (70 kg) as group 1 (30 kg). Note that these averages match the simple summary statistics above.

To perform one-sided tests, you first perform the corresponding two-sided Wald test. Then you can use the results to calculate the test statistic and p-value for the one-sided test. So now we do the two-sided test on the averages: group 1 minus group 2 is equal to group 1 minus group 3. This can be accomplished like this:

We can see that the p-value is effectively zero (last row), so we reject the null that the two differences are equal. Note that Stata has simplified our hypothesis into testing that Group 3 and Group 2 have the same average weight, or that their difference is zero.

When the estimated difference is positive, you can calculate the one-sided p-values directly from the test output by dividing by two like this:

Here were would reject the null that the difference in differences (DID) is zero because the p-value is tiny (first line), but we cannot reject the null that the $\text{DID} \ge 0$ since the p-value is large (second line).

When the difference is negative, you will need to swap r(p)/2 and 1-r(p)/2 above.

Division by 2 is easy, but you can also do the following. The idea is that the Wald test given above is an F test with 1 numerator degree of freedom and 45 denominator degrees of freedom. The Student’s t distribution is related to the F distribution in that the square of the Student’s t distribution with d degrees of freedom is equivalent to the F distribution with 1 numerator degree of freedom and d denominator degrees of freedom. As long as the F test has 1 numerator degree of freedom, the square root of the F statistic (79.21) is the absolute value of the t statistic for the one-sided test. To determine whether this t statistic is positive or negative, you need to determine whether the difference is positive or negative. To do this, you can use the sign() function. So now we can get all the pieces we need and do the one-sided tests:

Note that this matches the division results we got above.

There is a somewhat more intuitive way that also demonstrates what to do when z statistics are reported instead of t statistics. In these cases, you will get a chi-squared test instead of an F test. The relationship between the standard normal distribution and the chi-squared distribution is similar to the relationship between the Student’s t distribution and the F distribution. In fact, the square root of the chi-squared distribution with 1 degree of freedom is the standard normal distribution. Therefore, one-sided z tests can be performed similarly to one-sided t tests:

I find this a bit more intuitive, since it returns the DID as if it was an estimation command, with all the "fixin's": we can see that the DID is 22, we get its standard error of 2.5, and also confidence interval that excludes zero. We know the sign and can also just do the division by zero.

For the binary outcome, you can use a probit or logit or just an LPM (a regression, but with het-robust errors). Everything after is the same as above. The output will generally be very similar.

Stata Code:

- $\begingroup$ Thank you for such a clear explanation and code Dimitriy! $\endgroup$ – Helen Miller Commented Dec 4, 2020 at 7:33
- $\begingroup$ (+1) Nicely done. $\endgroup$ – chl Commented Dec 4, 2020 at 9:26
- $\begingroup$ Thank you both for the kind words. I think I finally understood one-sided testing in my early middle ages, so glad this is helping others. $\endgroup$ – dimitriy Commented Dec 4, 2020 at 9:53
- $\begingroup$ Hi. Is there any non-parametric alternative to this? Something similar to Wilcoxon/Mann-Whitney tests? Thanks! $\endgroup$ – amedicalenthusiast Commented Aug 12, 2023 at 2:09
- $\begingroup$ @amedicalenthusiast You can do a one-sided Wilcoxon, which is nonparametric. You just need to change the alternative to either less or greater since the default is typically two-sided. $\endgroup$ – dimitriy Commented Aug 14, 2023 at 16:22

## Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

## Not the answer you're looking for? Browse other questions tagged hypothesis-testing stata or ask your own question .

- Featured on Meta
- Upcoming sign-up experiments related to tags

## Hot Network Questions

- What kind of sequence is between an arithmetic and a geometric sequence?
- Could a transparent frequency-altering material be possible?
- What is the original source of this Sigurimi logo?
- Less ridiculous way to prove that an Ascii character compares equal with itself in Coq
- Were there engineers in airship nacelles, and why were they there?
- Next date in the future such that all 8 digits of MM/DD/YYYY are all different and the product of MM, DD and YY is equal to YYYY
- Visit USA via land border for French citizen
- ModSecurity rules that block user-agents - Hosting provider warn me not to remove this rule
- How are "pursed" and "rounded" synonymous?
- Why depreciation is considered a cost to own a car?
- How to produce this table: Probability datatable with multirow
- Is there a way to non-destructively test whether an Ethernet cable is pure copper or copper-clad aluminum (CCA)?
- How can a landlord receive rent in cash using western union
- How to make D&D easier for kids?
- Why Owasp-crs does not allow Content-Type: application/x-www-form-urlencoded
- Is Légal’s reported “psychological trick” considered fair play or unacceptable conduct under FIDE rules?
- Trying to determine what this small glass-enclosed item is
- How will the ISS be decommissioned?
- Have children's car seats not been proven to be more effective than seat belts alone for kids older than 24 months?
- Why potential energy is not considered in the internal energy of diatomic molecules?
- Could space habitats have large transparent roofs?
- What does ‘a grade-hog’ mean?
- Is there an image viewer for ubuntu that will read/apply xmp sidecars?
- bug with beamer and lastpage?

## Lesson 7: Two-Sample Hypothesis Tests in Stata

Test the equality of two sample means using data from the EG DIB evaluation.

## Empowering districts to improve administrative data quality in India

27 June 2024

## Empowering education through evidence in Cambodia

13 June 2024

## Ensuring quality data collection at scale: Best practices from a multi-sector multi-respondent survey

6 June 2024

## Tom Wein launches Marketplace Dignity book

3 June 2024

## Call for partners – IDinsight Dignity Initiative Randomized Controlled Trial (RCT)

16 May 2024

## Request for Partners: What works for more respectful development?

Access to health services: kilifi county case study.

15 May 2024

## How DataDelta created a data verification strategy to support local development efforts in India

Idinsight s’associe au millennium challenge account sénégal (mca) pour une initiative en faveur de l’électricité.

14 May 2024

## IDinsight Partners with Millennium Challenge Account Senegal (MCA) for Electricity Initiative

Related content.

9 September 2022

## Intro to the Lesson

12 September 2022

## Lesson Agenda and Dataset

Lesson 1: the stata interface (1): stata windows, stay up-to-date with idinsight.

Username or Email Address

Remember Me

Registration confirmation will be emailed to you.

- Skip to primary navigation
- Skip to main content
- Skip to primary sidebar

Institute for Digital Research and Education

## FAQ: What are the differences between one-tailed and two-tailed tests?

When you conduct a test of statistical significance, whether it is from a correlation, an ANOVA, a regression or some other kind of test, you are given a p-value somewhere in the output. If your test statistic is symmetrically distributed, you can select one of three alternative hypotheses. Two of these correspond to one-tailed tests and one corresponds to a two-tailed test. However, the p-value presented is (almost always) for a two-tailed test. But how do you choose which test? Is the p-value appropriate for your test? And, if it is not, how can you calculate the correct p-value for your test given the p-value in your output?

## What is a two-tailed test?

First let’s start with the meaning of a two-tailed test. If you are using a significance level of 0.05, a two-tailed test allots half of your alpha to testing the statistical significance in one direction and half of your alpha to testing statistical significance in the other direction. This means that .025 is in each tail of the distribution of your test statistic. When using a two-tailed test, regardless of the direction of the relationship you hypothesize, you are testing for the possibility of the relationship in both directions. For example, we may wish to compare the mean of a sample to a given value x using a t-test. Our null hypothesis is that the mean is equal to x . A two-tailed test will test both if the mean is significantly greater than x and if the mean significantly less than x . The mean is considered significantly different from x if the test statistic is in the top 2.5% or bottom 2.5% of its probability distribution, resulting in a p-value less than 0.05.

## What is a one-tailed test?

Next, let’s discuss the meaning of a one-tailed test. If you are using a significance level of .05, a one-tailed test allots all of your alpha to testing the statistical significance in the one direction of interest. This means that .05 is in one tail of the distribution of your test statistic. When using a one-tailed test, you are testing for the possibility of the relationship in one direction and completely disregarding the possibility of a relationship in the other direction. Let’s return to our example comparing the mean of a sample to a given value x using a t-test. Our null hypothesis is that the mean is equal to x . A one-tailed test will test either if the mean is significantly greater than x or if the mean is significantly less than x , but not both. Then, depending on the chosen tail, the mean is significantly greater than or less than x if the test statistic is in the top 5% of its probability distribution or bottom 5% of its probability distribution, resulting in a p-value less than 0.05. The one-tailed test provides more power to detect an effect in one direction by not testing the effect in the other direction. A discussion of when this is an appropriate option follows.

## When is a one-tailed test appropriate?

Because the one-tailed test provides more power to detect an effect, you may be tempted to use a one-tailed test whenever you have a hypothesis about the direction of an effect. Before doing so, consider the consequences of missing an effect in the other direction. Imagine you have developed a new drug that you believe is an improvement over an existing drug. You wish to maximize your ability to detect the improvement, so you opt for a one-tailed test. In doing so, you fail to test for the possibility that the new drug is less effective than the existing drug. The consequences in this example are extreme, but they illustrate a danger of inappropriate use of a one-tailed test.

So when is a one-tailed test appropriate? If you consider the consequences of missing an effect in the untested direction and conclude that they are negligible and in no way irresponsible or unethical, then you can proceed with a one-tailed test. For example, imagine again that you have developed a new drug. It is cheaper than the existing drug and, you believe, no less effective. In testing this drug, you are only interested in testing if it less effective than the existing drug. You do not care if it is significantly more effective. You only wish to show that it is not less effective. In this scenario, a one-tailed test would be appropriate.

## When is a one-tailed test NOT appropriate?

Choosing a one-tailed test for the sole purpose of attaining significance is not appropriate. Choosing a one-tailed test after running a two-tailed test that failed to reject the null hypothesis is not appropriate, no matter how "close" to significant the two-tailed test was. Using statistical tests inappropriately can lead to invalid results that are not replicable and highly questionable–a steep price to pay for a significance star in your results table!

## Deriving a one-tailed test from two-tailed output

The default among statistical packages performing tests is to report two-tailed p-values. Because the most commonly used test statistic distributions (standard normal, Student’s t) are symmetric about zero, most one-tailed p-values can be derived from the two-tailed p-values.

Below, we have the output from a two-sample t-test in Stata. The test is comparing the mean male score to the mean female score. The null hypothesis is that the difference in means is zero. The two-sided alternative is that the difference in means is not zero. There are two one-sided alternatives that one could opt to test instead: that the male score is higher than the female score (diff > 0) or that the female score is higher than the male score (diff < 0). In this instance, Stata presents results for all three alternatives. Under the headings Ha: diff < 0 and Ha: diff > 0 are the results for the one-tailed tests. In the middle, under the heading Ha: diff != 0 (which means that the difference is not equal to 0), are the results for the two-tailed test.

Two-sample t test with equal variances ------------------------------------------------------------------------------ Group | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- male | 91 50.12088 1.080274 10.30516 47.97473 52.26703 female | 109 54.99083 .7790686 8.133715 53.44658 56.53507 ---------+-------------------------------------------------------------------- combined | 200 52.775 .6702372 9.478586 51.45332 54.09668 ---------+-------------------------------------------------------------------- diff | -4.869947 1.304191 -7.441835 -2.298059 ------------------------------------------------------------------------------ Degrees of freedom: 198 Ho: mean(male) - mean(female) = diff = 0 Ha: diff < 0 Ha: diff != 0 Ha: diff > 0 t = -3.7341 t = -3.7341 t = -3.7341 P < t = 0.0001 P > |t| = 0.0002 P > t = 0.9999

Note that the test statistic, -3.7341, is the same for all of these tests. The two-tailed p-value is P > |t|. This can be rewritten as P(>3.7341) + P(< -3.7341). Because the t-distribution is symmetric about zero, these two probabilities are equal: P > |t| = 2 * P(< -3.7341). Thus, we can see that the two-tailed p-value is twice the one-tailed p-value for the alternative hypothesis that (diff < 0). The other one-tailed alternative hypothesis has a p-value of P(>-3.7341) = 1-(P<-3.7341) = 1-0.0001 = 0.9999. So, depending on the direction of the one-tailed hypothesis, its p-value is either 0.5*(two-tailed p-value) or 1-0.5*(two-tailed p-value) if the test statistic symmetrically distributed about zero.

In this example, the two-tailed p-value suggests rejecting the null hypothesis of no difference. Had we opted for the one-tailed test of (diff > 0), we would fail to reject the null because of our choice of tails.

The output below is from a regression analysis in Stata. Unlike the example above, only the two-sided p-values are presented in this output.

Source | SS df MS Number of obs = 200 -------------+------------------------------ F( 2, 197) = 46.58 Model | 7363.62077 2 3681.81039 Prob > F = 0.0000 Residual | 15572.5742 197 79.0486001 R-squared = 0.3210 -------------+------------------------------ Adj R-squared = 0.3142 Total | 22936.195 199 115.257261 Root MSE = 8.8909 ------------------------------------------------------------------------------ socst | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- science | .2191144 .0820323 2.67 0.008 .0573403 .3808885 math | .4778911 .0866945 5.51 0.000 .3069228 .6488594 _cons | 15.88534 3.850786 4.13 0.000 8.291287 23.47939 ------------------------------------------------------------------------------

For each regression coefficient, the tested null hypothesis is that the coefficient is equal to zero. Thus, the one-tailed alternatives are that the coefficient is greater than zero and that the coefficient is less than zero. To get the p-value for the one-tailed test of the variable science having a coefficient greater than zero, you would divide the .008 by 2, yielding .004 because the effect is going in the predicted direction. This is P(>2.67). If you had made your prediction in the other direction (the opposite direction of the model effect), the p-value would have been 1 – .004 = .996. This is P(<2.67). For all three p-values, the test statistic is 2.67.

Your Name (required)

Your Email (must be a valid email for us to receive the report!)

Comment/Error Report (required)

How to cite this page

- © 2021 UC REGENTS

## 1 item has been added to your cart.

## Stata/MP4 Annual License (download)

Introducing statanow ™ →.

New in Stata 18

Disciplines

- Which Stata is right for me?
- Supported platforms
- Stata Bookstore

Stata Press

Stata Journal

Order Stata

- Request a quote
- Purchasing FAQs

Classroom and web training

Organizational training

Video tutorials

- Documentation

Teaching with Stata

Third-party courses

Web resources

- Ready. Set. Go Stata.
- Installation Guide
- Register Stata

Free webinars

- Technical services
- Examples and datasets
- Author Support Program
- Editor Support Program
- Stata Conferences
- 2024 Stata Conference
- The Stata Blog
- Social media

News and events

- International resellers

Customer service

- Change registration
- Change address
- Subscribe to Stata News
- Sign up for alerts

Search stata.com

- Stata/BE network 2-year maintenance Quantity: 196 Users Qty: 1 $11,763.00
- Create an account
- Email alerts
- Subscribe to email alerts

## The results from estimation commands display only two-sided tests for the coefficients. How can I perform a one-sided test?

-->Title | One-sided tests for coefficients | |

Author | Kristin MacDonald, StataCorp | |

July 2006; minor revision May 2015 |

Estimation commands provide a t test or z test for the null hypothesis that a coefficient is equal to zero. The test command can perform Wald tests for simple and composite linear hypotheses on the parameters, but these Wald tests are also limited to tests of equality.

## One-sided t tests

To perform one-sided tests, you can first perform the corresponding two-sided Wald test. Then you can use the results to calculate the test statistic and p -value for the one-sided test. Let’s say that you perform the following regression:

Source | SS df MS | Number of obs = 74 | |

F(2, 71) = 14.74 | |||

Model | 186321280 2 93160639.9 | Prob > F = 0.0000 | |

Residual | 448744116 71 6320339.67 | R-squared = 0.2934 | |

Adj R-squared = 0.2735 | |||

Total | 635065396 73 8699525.97 | Root MSE = 2514 |

price | Coefficient Std. err. t P>|t| [95% conf. interval] | |

mpg | -49.51222 86.15604 -0.57 0.567 -221.3025 122.278 | |

weight | 1.746559 .6413538 2.72 0.008 .467736 3.025382 | |

_cons | 1946.069 3597.05 0.54 0.590 -5226.245 9118.382 | |

If you wish to test that the coefficient on weight , β weight , is negative (or positive), you can begin by performing the Wald test for the null hypothesis that this coefficient is equal to zero.

The Wald test given here is an F test with 1 numerator degree of freedom and 71 denominator degrees of freedom. The Student’s t distribution is directly related to the F distribution in that the square of the Student’s t distribution with d degrees of freedom is equivalent to the F distribution with 1 numerator degree of freedom and d denominator degrees of freedom.

As long as the F test has 1 numerator degree of freedom, the square root of the F statistic is the absolute value of the t statistic for the one-sided test. To determine whether this t statistic is positive or negative, you need to determine whether the fitted coefficient is positive or negative. To do this, you can use the sign() function.

Then, using the ttail() function along with the returned results from the test command, you can calculate the p -values for the one-sided tests in the following manner:

In the special case where you are interested in testing whether a coefficient is greater than, less than, or equal to zero, you can calculate the p -values directly from the regression output. When the estimated coefficient is positive, as for weight , you can do so as follows:

H : β = 0 | -value = 0.008 (given in regression output) |

H : β <= 0 | -value = 0.008/2 = 0.004 |

H : β >= 0 | -value = 1 − (0.008/2) = 0.996 |

When the estimated coefficient is negative, as for mpg , the same code can be used:

However, to calculate the p -values from the regression output directly, you use the following formulas:

H : β = 0 | -value = 0.567 (given in regression output) |

H : β <= 0 | -value = 1 − (0.567/2) = 0.717 |

H : β >= 0 | -value = 0.567/2 = 0.284 |

On the other hand, if you want to perform a test such as H 0 : β weight <= 1, you cannot calculate the p -value directly from the regression results. Here you would have to perform the Wald test first.

## One-sided z tests

In the output for certain estimation commands, you will find that z statistics are reported instead of t statistics. In these cases, when you use the test command, you will get a chi-squared test instead of an F test. The relationship between the standard normal distribution and the chi-squared distribution is similar to the relationship between the Student’s t distribution and the F distribution. In fact, the square root of the chi-squared distribution with 1 degree of freedom is the standard normal distribution. Therefore, one-sided z tests can be performed similarly to one-sided t tests. For example,

union | Coefficient Std. err. z P>|z| [95% conf. interval] | |

age | .0149252 .0036634 4.07 0.000 .007745 .0221055 | |

grade | .1130089 .0177088 6.38 0.000 .0783002 .1477175 | |

_cons | -4.313313 .2426307 -17.78 0.000 -4.788861 -3.837766 | |

/lnsig2u | 1.800793 .046732 1.7092 1.892386 | |

sigma_u | 2.460578 .0574939 2.350434 2.575884 | |

rho | .6479283 .0106604 .6267624 .6685287 | |

Here the test command returns r(chi2) , which can be used along with the normal() function to calculate the appropriate p -values.

Finally, if you want to perform a test of inequality for two of your coefficients, such as H 0 : β age >= β grade , you would first perform the following Wald test:

Then calculate the appropriate p -value:

Again, this approach (performing a Wald test and using the results to calculate the p -value for a one-sided test) is appropriate only when the Wald F statistic has 1 degree of freedom in the numerator or the Wald chi-squared statistic has 1 degree of freedom. The distributional relationships discussed above are not valid if these degrees of freedom are larger than 1.

All features

Statalist: The Stata Forum

Technical support

© Copyright 1996–2024 StataCorp LLC. All rights reserved.

Terms of use | Privacy policy | Contact us

## We use cookies

We use cookies to ensure that we give you the best experience on our website—to enhance site navigation, to analyze usage, and to assist in our marketing efforts. By continuing to use our site, you consent to the storing of cookies on your device and agree to delivery of content, including web fonts and JavaScript, from third party web services.

Cookie Settings

## Privacy policy

Last updated: 16 November 2022

StataCorp LLC (StataCorp) strives to provide our users with exceptional products and services. To do so, we must collect personal information from you. This information is necessary to conduct business with our existing and potential customers. We collect and use this information only where we may legally do so. This policy explains what personal information we collect, how we use it, and what rights you have to that information.

## Required cookies

These cookies are essential for our website to function and do not store any personally identifiable information. These cookies cannot be disabled.

## Advertising and performance cookies

This website uses cookies to provide you with a better user experience. A cookie is a small piece of data our website stores on a site visitor's hard drive and accesses each time you visit so we can improve your access to our site, better understand how you use our site, and serve you content that may be of interest to you. For instance, we store a cookie when you log in to our shopping cart so that we can maintain your shopping cart should you not complete checkout. These cookies do not directly store your personal information, but they do support the ability to uniquely identify your internet browser and device.

Please note: Clearing your browser cookies at any time will undo preferences saved here. The option selected here will apply only to the device you are currently using.

- [email protected]
- Connecting and sharing with us

- Entrepreneurship
- Growth of firm
- Sales Management
- Retail Management
- Import – Export
- International Business
- Project Management
- Production Management
- Quality Management
- Logistics Management
- Supply Chain Management
- Human Resource Management
- Organizational Culture
- Information System Management
- Corporate Finance
- Stock Market
- Office Management
- Theory of the Firm
- Management Science
- Microeconomics
- Research Process
- Experimental Research
- Research Philosophy
- Management Research
- Writing a thesis
- Writing a paper
- Literature Review
- Action Research
- Qualitative Content Analysis
- Observation
- Phenomenology
- Statistics and Econometrics
- Questionnaire Survey
- Quantitative Content Analysis
- Meta Analysis

## Hypothesis Tests with Linear Regression by using Stata

Two types ofhypothesis tests appear in regress output tables. As with other common hypothesis tests, they begin from the assumption that observations in the sample at hand were drawn randomly and independently from an infinitely large population.

- Overall F test: The F statistic at the upper right in the regression table evaluates the null hypothesis that in the population, coefficients on all the model’s x variables equal zero.
- Individual t tests: The third and fourth columns of the regression table contain t tests for each individual regression coefficient. These evaluate the null hypotheses that in the population, the coefficient on each particular x variable equals zero.

The t test probabilities are two-sided. For one-sided tests, divide these p-values in half.

In addition to these standard F and t tests, Stata can perform F tests of user-specified hypotheses. The test command refers back to the most recently fitted model such as anova or regress. Returning to our four-predictor regression example, suppose we with to test the null hypothesis that both adfert and chldmort (considered jointly) have zero effect.

While the individual null hypotheses point in opposite directions (effect of chldmort significant, adfert not), the joint hypothesis that coefficients on chldmort and adfert both equal zero can reasonably be rejected (p < .00005). Such tests on subsets of coefficients are useful when we have several conceptually related predictors or when individual coefficient estimates appear unreliable due to multicollinearity.

test could duplicate the overall F test:

test also could duplicate the individual-coefficient tests. Regarding the coefficient on school, for example, the F statistic obtained by test equals the square of the t statistic in the regression table, 2.25 = (-1.50) 2 , and yields exactly the same p-value:

Applications of test more useful in advanced work (although not meaningful for the life- expectancy example at hand) include the following.

- Test whether a coefficient equals a specified constant. For example, to test the null hypothesis that the coefficient on school equals 1 (H 0 😛 1 = 1), instead of testing the usual null hypothesis that it equals 0 (H 0 😛 1 = 0), type

. test school = 1

- Test whether two coefficients are equal. For example, the following command evaluates the null hypothesis H 0 😛 2 = P 3

. test loggdp = adfert

- Finally, test understands some algebraic expressions. We could request something like the following, which would test H 0 😛 2 = (P 3 + P 4 ) / 100

. test school = (loggdp + adfert)/100

Consult help test for more information and examples.

Source: Hamilton Lawrence C. (2012), Statistics with STATA: Version 12 , Cengage Learning; 8th edition.

28 Sep 2022

29 Sep 2022

26 Sep 2022

## 1 thoughts on “ Hypothesis Tests with Linear Regression by using Stata ”

I haven?¦t checked in here for some time because I thought it was getting boring, but the last few posts are good quality so I guess I will add you back to my daily bloglist. You deserve it my friend 🙂

## Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

Username or email address *

Password *

Log in Remember me

Lost your password?

- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
- OverflowAI GenAI features for Teams
- OverflowAPI Train & fine-tune LLMs
- Labs The future of collective knowledge sharing
- About the company Visit the blog

## Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

## How do I calculate the p-value of a one-tailed test in Stata?

I have the following model: ln(MPG_{i}) = \beta _{0} + \beta {1}WEIGHT {i} + \beta {1}FOREIGN {i} + \beta {3}FOREIGN {i} * WEIGHT_{i} + \varepsilon_{i,j}

I want to use the test command to test whether the coefficient on $\beta_{3} >0.5$ in STATA.

I have used the following code and obtain this result:

test 1.foreign#c.weight = 0.5001

( 1) 1.foreign#c.weight = .5001

So we reject our null, since the p-value is very small.

But the problem is that this for a two-tailed test.

My goal is to get the t-test value for this left-tailed test and then to store it. And then use the t-test to compute its p-value.

After computing the p-value, I decide whether or not to reject the null. I am certain that I would reject the null and the p-value would be quite small. Just need some help in figuring out how to code it the right way.

EDIT: I have tried using these commands:

The last command spits out a value of 0. Now is this the p-value of the left-sided t-test?

- Do you already know how to conduct this test and only want to learn Stata commands to do it, or is your problem perhaps also related to not knowing what test to use, how to calculate it, or how to interpret it? Could you be specific about what kind of help you need? – whuber Commented Feb 2, 2015 at 20:10
- @whuber It's the first part. I know the test, but would want to learn the Stata commands to do it. – OGC Commented Feb 2, 2015 at 21:43

This is covered in this FAQ .

Here's the relevant code for testing that a coefficient is 0.5:

## Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

## Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

## Not the answer you're looking for? Browse other questions tagged stata or ask your own question .

- Featured on Meta
- Upcoming sign-up experiments related to tags
- Policy: Generative AI (e.g., ChatGPT) is banned
- What makes a homepage useful for logged-in users
- The [lib] tag is being burninated

## Hot Network Questions

- Can my IP be found on Telegram by malicious people?
- Were there engineers in airship nacelles, and why were they there?
- Is it consistent with ZFC that the real line is approachable by sets with no accumulation points?
- What distinguishes boosts from general Lorentz transformations?
- What is the relationship between gravitation, centripetal and centrifugal force on the Earth?
- Trying to determine what this small glass-enclosed item is
- What could explain that small planes near an airport are perceived as harassing homeowners?
- Weird behavior by car insurance - is this legit?
- How many steps are needed to turn one "a" into 100,000 "a"s using only the three functions of "select all", "copy" and "paste"?
- Correlation for Small Dataset?
- Could space habitats have large transparent roofs?
- DSP Puzzle: Advanced Signal Forensics
- How do guitarists remember what note each string represents when fretting?
- Why depreciation is considered a cost to own a car?
- How do you say "living being" in Classical Latin?
- Why was the animal "Wolf" used in the title "The Wolf of Wall Street (2013)"?
- What is the original source of this Sigurimi logo?
- Why can Ethernet NICs bridge to VirtualBox and most Wi-Fi NICs don't?
- bug with beamer and lastpage?
- What actual purpose do accent characters in ISO-8859-1 and Windows 1252 serve?
- Old book about a man who finds an abandoned house with a portal to another world
- Why Owasp-crs does not allow Content-Type: application/x-www-form-urlencoded
- Reconstructing Euro results
- ModSecurity rules that block user-agents - Hosting provider warn me not to remove this rule

- Log in with

- Search in titles only Search in General only Advanced Search Search
- Forums for Discussing Stata
- You are not logged in. You can browse but not post. Login or Register by clicking 'Login or Register' at the top-right of this page. For more information on Statalist, see the FAQ .

## Announcement

- Latest Activity
- Time All Time Today Last Week Last Month
- Show All Discussions only Photos only Videos only Links only Polls only

- Join Date: Nov 2017

## One sided joint hypothesis test

- Join Date: Apr 2014
- Posts: 4348

- © Copyright 2024 StataCorp LLC
- Terms of use

## IMAGES

## VIDEO

## COMMENTS

Example: Two Sample t-test in Stata. Researchers want to know if a new fuel treatment leads to a change in the average mpg of a certain car. To test this, they conduct an experiment in which 12 cars receive the new fuel treatment and 12 cars do not. Perform the following steps to conduct a two sample t-test to determine if there is a difference ...

The test indicates that the underlying mean is not 20 with a signiﬁcance level of 5.8%. Two-sample t test Example 2: Two-sample ttest using groups We are testing the effectiveness of a new fuel additive. We run an experiment in which 12 cars are given the fuel treatment and 12 cars are not. The results of the experiment are as follows ...

Title stata.com table hypothesis tests ... r z test statistics for r b r z abs absolute value of r z ... Two-sample test of proportions Male: Number of obs = 4915 Female: Number of obs = 5434 Group Mean Std. err. z P>|z| [95% conf. interval] Male .0441506 .0029302 .0384074 .0498937

test x1 + x2 = 4 Test the equality of two linear expressions involving coefﬁcients on x1 and x2 test 2*x1 = 3*x2 Shorthand varlist notation Joint test that all coefﬁcients on the indicators for a are equal to 0 testparm i.a Joint test that all coefﬁcients on the indicators for a and b are equal to 0 testparm i.a i.b

If the p-value associated with the t-test is not small (p > 0.05), then the null hypothesis is not rejected and you can conclude that the mean is not different from the hypothesized value. In this example, the t-statistic is 4.1403 with 199 degrees of freedom. The corresponding two-tailed p-value is .0001, which is less than 0.05.

We run the following treatment regressions for outcome j at time t: Y (j,t) = a + b1*treat1+b2*treat2+b3*treat3+b4*treat4 + c1*y (j,0) + d'X + e (j,t) With 5 outcomes and 4 treatments, we have 20 hypothesis tests and thus 20 p-values. Here's an example from a recent experiment of mine (where the outcomes are firm survival, and four types of ...

About Press Copyright Contact us Creators Advertise Developers Terms Privacy Policy & Safety How YouTube works Test new features NFL Sunday Ticket Press Copyright ...

This unit describes the use of Stata for estimation and hypothesis tests of data in one, two and more than two samples. Important! Be sure that you have already produced your data descriptions (See again, ... = 0.000079 (two-sided test) Key: The 2-sided test is statistically significant (p = .00008). Reject the null. . * Command HISTOGRAM with ...

updated-overview-multiple-hypothesis-testing-commands-stata 11/16. FWER Corrections and Improvements in Power Figure: Simulated Power to Reject False Null Hypothesis 0.2.4.6.8 Proportion of Nulls Correctly Rejected 1 0 .2 .4 .6 .8 1 Value for b Uncorrected Bonferroni Holm Romano-Wolf (a) ...

This article is part of the Stata for Students series. If you are new to Stata we strongly recommend reading all the articles in the Stata Basics section. t-tests are frequently used to test hypotheses about the population mean of a variable. The command to run one is simply ttest, but the syntax will depend on the hypothesis you want to test.

This output gives both of the one-sided tests as well as the two-sided test. Assuming that we were looking for any difference, we would use the two-sided test and conclude that no statistically significant difference was found (p=.5565). See also. Stata Code Fragment: Descriptives, ttests, Anova and Regression; Stata Class Notes: Analyzing Data

Note that Stata has simplified our hypothesis into testing that Group 3 and Group 2 have the same average weight, or that their difference is zero. When the estimated difference is positive, you can calculate the one-sided p-values directly from the test output by dividing by two like this:

Lesson 1: The Stata Interface (1): Stata Windows. Test the equality of two sample means using data from the EG DIB evaluation.

performed using hypothesis testing. Speciﬁcally, we consider the null hypothesis H 0: 2 = 1 versus the two-sided alternative hypothesis H a: 2 6= 1, the upper one-sided alternative H a: 2 > 1, or the lower one-sided alternative H a: 2 < 1. The considered two-sample tests rely on the assumption that the two random samples are normally

Because the most commonly used test statistic distributions (standard normal, Student's t) are symmetric about zero, most one-tailed p-values can be derived from the two-tailed p-values. Below, we have the output from a two-sample t-test in Stata. The test is comparing the mean male score to the mean female score.

Hi Amalie, Please read the FAQ, in particular #12.1, what to say about the the commands and your problem. The article that Sebastian posted does not involve an explicit hypothesis test of the age coefficient, so we cannot see exactly which commands you typed that led you to the -test age- statement.

How can you with Stata test the null hypothesis against the alternative hypothesis. If I have the hypothesis H_0:\beta_1=\beta_2=0 against H_A:\beta_1 ≠ \beta_2 ≠ 0. What will the code be? ... The two-sided p-value is stored in r(p):. display r(p) .94664298 Share. Improve this answer. Follow

Estimation commands provide a t test or z test for the null hypothesis that a coefficient is equal to zero. The test command can perform Wald tests for simple and composite linear hypotheses on the parameters, but these Wald tests are also limited to tests of equality. One-sided t tests . To perform one-sided tests, you can first perform the corresponding two-sided Wald test.

The t test probabilities are two-sided. For one-sided tests, divide these p-values in half. In addition to these standard F and t tests, Stata can perform F tests of user-specified hypotheses. The test command refers back to the most recently fitted model such as anova or regress. ... For example, to test the null hypothesis that the ...

I have used the following code and obtain this result: test 1.foreign#c.weight = 0.5001. ( 1) 1.foreign#c.weight = .5001. F( 1, 70) = 4.9e+07. Prob > F = 0.0000. So we reject our null, since the p-value is very small. But the problem is that this for a two-tailed test. My goal is to get the t-test value for this left-tailed test and then to ...

One sided joint hypothesis test. But running them jointly doesn't seem to be covered. Any help greatly appreciated! You'll increase your chances of a helpful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex. Also, assume we are not from your area, and ...