{"id":977,"date":"2017-11-10T23:06:55","date_gmt":"2017-11-11T04:06:55","guid":{"rendered":"http:\/\/www.kaikaichen.com\/?p=977"},"modified":"2017-12-08T17:07:52","modified_gmt":"2017-12-08T22:07:52","slug":"commonly-used-stata-commands-to-deal-with-potential-outliers","status":"publish","type":"post","link":"https:\/\/www.kaichen.work\/?p=977","title":{"rendered":"Commonly used Stata commands to deal with potential outliers"},"content":{"rendered":"<p>In accounting archival research, we often take it for granted that we must do something to deal with potential outliers before we run a regression. The commonly used methods are: truncate, winsorize, studentized residuals, and Cook&#8217;s distance. I discuss in this post which Stata command to use to implement these four methods.<\/p>\n<p>First of all, why and how we deal with potential outliers is perhaps one of the messiest issues that accounting researchers will encounter, because no one ever gives a definitive and satisfactory answer. In my opinion, only outliers resulting from apparent data errors should be deleted from the sample. That said, this post is not going to answer that messy question; instead, the purpose of this post is to summarize the Stata commands for commonly used methods of dealing with outliers (even if we are not sure whether these methods are appropriate\u2014we all know that is true in accounting research!). Let&#8217;s start.<\/p>\n<p><strong>Truncate and winsorize<\/strong><\/p>\n<p>In my opinion, the best Stata commands to do truncate and winsorize are <code>truncateJ<\/code>\u00a0and <code>winsorizeJ<\/code>\u00a0written by Judson Caskey. I will save time to explain why, but simply highly recommend his work. Please see his website <a href=\"https:\/\/sites.google.com\/site\/judsoncaskey\/data\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>To install these two user-written commands, you can type:<\/p>\n<p><code>net from https:\/\/sites.google.com\/site\/judsoncaskey\/data<\/code><br \/>\n<code>net install utilities.pkg<\/code><\/p>\n<p>After the installation, you can type <code>help truncateJ<\/code>\u00a0or <code>help winsorizeJ<\/code>\u00a0to learn how to use these two commands.<\/p>\n<p><strong>Studentized residuals<\/strong><\/p>\n<p>The first step is to run a regression without specifying any <code>vce<\/code>\u00a0parameter in Stata (i.e., not using robust or clustered error terms). Suppose the dependent variable is <code>y<\/code>, and independent variables are <code>x1<\/code>\u00a0and <code>x2<\/code>. The first step should look like this:<\/p>\n<p><code>regress y x1 x2<\/code><\/p>\n<p>Then, use the <code>predict<\/code>\u00a0command:<\/p>\n<p><code>predict rstu if e(sample), rstudent<\/code><\/p>\n<p>If the absolute value of <code>rstu<\/code>\u00a0exceed certain critical values, the data point will be considered as an outlier and be deleted from the final sample. Stata&#8217;s manual indicates that &#8220;studentized residuals can be interpreted as the t statistic for testing the significance of a dummy variable equal to 1 in the observation in question and 0 elsewhere. Such a dummy variable would effectively absorb the observation and so remove its influence in determining the other coefficients in the model.&#8221; To be honest, I do not fully understand this explanation, but since <code>rstu<\/code>\u00a0is a <em>t<\/em> statistics, the critical value for a traditional significance level should be applied, for example, 1.96 (or 2) for 5% significance level. That&#8217;s why in literature we often see that data points with absolute values of studentized residuals greater than 2 will be deleted. Some papers use the critical value of 3, which corresponds to 0.27% significance level, and seems to me not very reasonable.<\/p>\n<p>Now use the following command to drop &#8220;outliers&#8221; based on the critical value of 2:<\/p>\n<p><code>drop if abs(rstu) &gt; 2<\/code><\/p>\n<p>The last step is to re-run the regression, but this time we can add appropriate <code>vce<\/code>\u00a0parameters to address additional issues such as heteroskedasticity:<\/p>\n<p><code>regress y x1 x2, vce(robust)<\/code>, or<\/p>\n<p><code>regress y x1 x2, vce(cl gvkey)<\/code><\/p>\n<p><span style=\"color: #000000;\"><b>Cook&#8217;s distance<\/b><\/span><\/p>\n<p>This method is similar to studentized residuals. We predict a specific residual, namely Cook&#8217;s distance, and then delete any data points with Cook&#8217;s distance greater than 4\/N (Cook&#8217;s distance is always positive).<\/p>\n<p><code>regress y x1 x2<\/code><\/p>\n<p><code>predict cooksd if e(sample), cooksd<\/code><\/p>\n<p><code>drop if cooksd &gt; critical value<\/code><\/p>\n<p>Next, re-run the regression with appropriate <code>vce<\/code>\u00a0parameters:<\/p>\n<p><code>regress y x1 x2, vce(robust)<\/code>, or<\/p>\n<p><code>regress y x1 x2, vce(cl gvkey)<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>Lastly, I thank the authors of the following articles which I benefit from:<\/p>\n<p><a href=\"https:\/\/www3.nd.edu\/~rwilliam\/stats2\/l24.pdf\" target=\"_blank\" rel=\"noopener\">https:\/\/www3.nd.edu\/~rwilliam\/stats2\/l24.pdf<\/a><\/p>\n<p><a href=\"https:\/\/www.stat-d.si\/mz\/mz16\/coend16.pdf\" target=\"_blank\" rel=\"noopener\">https:\/\/www.stat-d.si\/mz\/mz16\/coend16.pdf<\/a><\/p>\n<p>A more formal and complete econometrics book is Belsley, D. A., E. Kuh, and R. E. Welsch. 1980. Regression Diagnostics: Identifying Influential Data and Sources of Collinearity. New York: Wiley.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In accounting archival research, we often take it for granted that we must do something to deal with potential outliers before we run a regression. The commonly used methods are: truncate, winsorize, studentized residuals, and Cook&#8217;s distance. I discuss in &hellip; <a href=\"https:\/\/www.kaichen.work\/?p=977\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/977"}],"collection":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=977"}],"version-history":[{"count":11,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/977\/revisions"}],"predecessor-version":[{"id":1017,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/977\/revisions\/1017"}],"wp:attachment":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}