{"id":26,"date":"2018-07-16T22:33:38","date_gmt":"2018-07-17T05:33:38","guid":{"rendered":"https:\/\/blogs.ubc.ca\/datawithstata\/?page_id=26"},"modified":"2019-05-14T02:42:23","modified_gmt":"2019-05-14T09:42:23","slug":"stata","status":"publish","type":"page","link":"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/stata\/","title":{"rendered":"Stata"},"content":{"rendered":"<p>These are simple examples of useful commands and options using 1978 auto data from <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr>. The commands are in\u00a0<strong>bold text<\/strong>;\u00a0variables and other inputs are in plain text for the sake of example.<\/p>\n<h2><span style=\"color: #dd3396;\"><em>Commands<\/em>: SET UP <\/span><\/h2>\n<div id=\"random-accordion-id-4\" class=\"accordion-shortcode  \"> <h3 ><a href=\"#do-files-0\" >Do-Files<\/a><\/h3><div id=\"do-files-0\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\"><strong>doedit<\/strong><\/td>\n<td style=\"width: 50%;\">Opens the Do-file editor. Here you can type a list of commands for your data analysis. The point of a Do-file is that you can reproduce the same results later, and you can revise it with more commands.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>#delimit ;<\/strong><\/td>\n<td style=\"width: 50%;\">(In Do-files only). Changes the line delimiter to a semicolon \"<strong>;<\/strong>\". All commands in the Do-file after this one must now end with a semicolon. This is helpful if you have a long command: you can split it into multiple lines in the do-file and mark the end of the entire command with a semi-colon. This makes for a cleaner output when the command is displayed in the results section upon execution.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>#delimit cr<\/strong><\/td>\n<td style=\"width: 50%;\">(In Do-files only). Resets the line delimiter to carriage return. All commands after this now end at the end of the line - a new line starts a new command. This is the default setting.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>do \"<\/strong>C:\\documents\\autoanalysis.do<strong>\"<\/strong><\/td>\n<td style=\"width: 50%;\">\u00a0Executes all of the commands from the Do-file \"autoanalysis\" in order. If any command contains an error (syntax, misspelling, etc.), <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> will execute the commands up to that line only before stopping. In this case, reopen the editor and correct any mistakes.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div> <h3 ><a href=\"#log-files-1\" >Log Files<\/a><\/h3><div id=\"log-files-1\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>log using\u00a0<\/strong>autoanalysis<strong>.log<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Creates a file that records all of the results of your data analysis in a log. Specifying \"<strong>.log<\/strong>\" records your output as a text file, otherwise it is recorded as a <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> file \"<strong>.smcl<\/strong>\" that opens in the viewer. The log file will be stored in the folder under the current directory.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>*<\/strong>\u00a0comment on data analysis<\/td>\n<td style=\"width: 50%; height: 24px;\">Starting a command line with\u00a0an asterisk \"<strong>*<\/strong>\" makes the command line act as simple text - it won't be interpreted as a command. This is helpful in do-files and log files as a way to leave notes on your analysis when you review the file later.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>log off\u00a0<\/strong><br \/>\n<strong>log on<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\"><strong>\"log off <\/strong>\" temporarily suspends the log file, and \"<strong>log on<\/strong>\" reopens it.\u00a0This is helpful if you want to perform some data analysis without including the results in the log file, and if you want to reopen the log file later in the same session.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>log close<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Ends the log file. Any commands submitted and their results will no longer be stored in the log file.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>log using\u00a0<\/strong>autoanalysis.log<strong>, append<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Reopens an existing log file. This lets you add more commands and results to the same log file.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>translate\u00a0<\/strong>autoanalysis<strong>.log<\/strong> autoanalysis<strong>.pdf<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Reformats the log file \"autoanalysis\"\u00a0 from a text file to a pdf file.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div> <h3 ><a href=\"#importing-data-2\" >Importing Data<\/a><\/h3><div id=\"importing-data-2\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\"><strong>cls<br \/>\n<\/strong><\/td>\n<td style=\"width: 50%;\">Clears the results window. As an alternative to the command\u00a0<strong>clear<\/strong>,\u00a0<strong>cls\u00a0<\/strong>keeps the data file in use<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>cd \u201c<\/strong>C:\\documents\\data<strong>\u201d<\/strong><\/td>\n<td style=\"width: 50%;\">Changes the working directory to the specified folder. Input the folder which contains the data file we want to use.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>use <\/strong>auto.dta<strong>, clear<\/strong><\/td>\n<td style=\"width: 50%;\">Loads a data set from the current directory. The option <strong>clear<\/strong> clears the current dataset from memory. For all examples we use the auto data file included in <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr>.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>import excel \u201c<\/strong>C:\\documents\\data\\auto.xlsx<strong>\u201d, sheet(\u201cSheet1\u201d) firstrow<\/strong><\/td>\n<td style=\"width: 50%;\">Imports the auto data if it were an excel file. <strong>sheet<\/strong> determines which worksheet to import, and <strong>firstrow<\/strong> imports the first row of the excel file as the variable names.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>import delimited \"<\/strong>auto<strong>.csv\", rowrange(<\/strong>1<strong>:<\/strong>74<strong>) colrange(<\/strong>1:12<strong>) varnames(<\/strong>1<strong>)<\/strong><\/td>\n<td style=\"width: 50%;\">Imports the auto data if it were a comma-separated values (.csv) file. Options\u00a0<strong>rowrange<\/strong> and\u00a0<strong>colrange<\/strong> specify ranges of rows (observations) and columns (variables) to import, respectively.\u00a0<strong>varnames<\/strong> specifies which row contains the variable names - in this case, the first row.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><h3 ><a href=\"#exporting-data-3\" >Exporting Data<\/a><\/h3><div id=\"exporting-data-3\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\"><strong>save\u00a0<\/strong>auto.dta<strong>, replace<\/strong><\/td>\n<td style=\"width: 50%;\">Saves the current data file and overwrites the old one. We can omit the\u00a0<strong>replace<\/strong> command if we want to save the data under a new name.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>export<\/strong>\u00a0<strong>excel \"<\/strong>autodata.xls<strong>\", firstrow (variables)<\/strong><\/td>\n<td style=\"width: 50%;\">\u00a0Saves the current data file as a new excel file. The\u00a0<strong>firstrow<\/strong> option uses the variable names as the first row of the excel file. Otherwise the variable names will be omitted.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><\/div><!-- #random-accordion-id-4end of accordion shortcode -->\n<h2><\/h2>\n<h2><span style=\"color: #dd3396;\"><em>Commands<\/em>: Data Management &amp; Analysis <\/span><\/h2>\n<div id=\"random-accordion-id-335\" class=\"accordion-shortcode  \"> <h3 ><a href=\"#summary-statistics-4\" >Summary Statistics<\/a><\/h3><div id=\"summary-statistics-4\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>describe\u00a0<\/strong>mpg price<\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays the variable type, format and value labels for\u00a0<em>mpg\u00a0<\/em>and\u00a0<em>price.<\/em><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>count\u00a0if<\/strong> foreign<strong> ==<\/strong> 1<\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Counts the number of observations that satisfy certain conditions. Here we count the number of foreign made cars.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>summarize\u00a0<\/strong>mpg price<strong>,\u00a0detail<\/strong><\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays summary statistics for variables\u00a0<em>mpg\u00a0<\/em>and\u00a0<em>price <\/em>(mean, standard deviation, minimum and maximum). Option\u00a0<strong>detail<\/strong> gives more statistics such as percentiles (50th percentile is the median), skewness, and kurtosis.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>codebook\u00a0<\/strong>mpg price<\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays variable type, summary statistics, percentiles, and number of missing values.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>inspect<\/strong>\u00a0mpg<\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays a simple histogram for\u00a0<em>mpg<\/em>. Also gives the numbers of observations with negative, zero, or positive values; unique values; and missing values.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>histogram\u00a0<\/strong>mpg<strong>,\u00a0bin(<\/strong>10<strong>)<\/strong><\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays a histogram of <em>mpg\u00a0<\/em>with parameters decided by <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr>. Option\u00a0<strong>bin(<\/strong>10<strong>)<\/strong> specifies number of bins. Width of each bin determined automatically by bin size and range of\u00a0<em>mpg.<\/em><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>browse<\/strong>\u00a0make mpg price<\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Opens a data browser for variables\u00a0<em>make, mpg,<\/em>\u00a0and<em> price.\u00a0<\/em>Helpful if you have many variables and want to focus on a subset of them.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>tabulate <\/strong>rep78<strong>,\u00a0missing<\/strong><\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays a one-way frequency table. Option\u00a0<strong>mi<\/strong> treats missing values as a separate category (otherwise observations withI missing values are ignored).\u00a0Tabulate works best for discrete variables, or variables with few unique values.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>tabulate\u00a0<\/strong>mpg foreign<\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays a two-way frequency table. For each value of the first variable\u00a0<em>mpg,\u00a0<\/em>we tabulate the frequency for each value of\u00a0<em>foreign<\/em>. It is important to list the variable with more unique values (<em>mpg<\/em>) first.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>tabstat\u00a0<\/strong>price weight mpg<strong>,\u00a0by (<\/strong>foreign<strong>) stat (mean sd n)<\/strong><\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays a table of summary statistics of\u00a0<em>price, weight,\u00a0<\/em>and\u00a0<em>mpg<\/em>. Option\u00a0<strong>by(<\/strong>...<strong>)<\/strong> generates separate statistics for each value of\u00a0<em>foreign<\/em>. Option\u00a0<strong>stat(<\/strong>...<strong>)<\/strong> determines which summary statistics to display (mean, standard deviation, and number of observations).<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>list\u00a0<\/strong>make price mpg\u00a0<strong>if\u00a0<\/strong>mpg <strong>&gt;=<\/strong> 30<\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Lists the values of\u00a0<em>make, price<\/em> and\u00a0<em>mpg\u00a0<\/em>for observations that satisfy the conditions determined by option\u00a0<strong>if<\/strong>.\u00a0In this case we list the values only for cars with mpg greater than or equal to 30.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 48.8326%; height: 24px;\"><strong>\u00a0correlate\u00a0<\/strong>mpg weight price<\/td>\n<td style=\"width: 78.5674%; height: 24px;\">Displays a correlation matrix for all specified variables.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><h3 ><a href=\"#generating-variables-5\" >Generating Variables<\/a><\/h3><div id=\"generating-variables-5\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\"><strong>generate\u00a0<\/strong>lprice <strong>=<\/strong> <strong>log(<\/strong>price<strong>)<\/strong><\/td>\n<td style=\"width: 50%;\">Creates a new variable based on a function of existing variables. Here we take the (natural)\u00a0<strong>logarithm\u00a0<\/strong>of the variable\u00a0<em>price<\/em>. The new variable\u00a0<em>lprice<\/em>\u00a0represents the log of price of every observation. This is a critical tool for model specification.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>generate\u00a0<\/strong>efficient\u00a0<strong>= 1<\/strong>\u00a0<strong>if\u00a0<\/strong>mpg\u00a0<strong>&gt;=\u00a0<\/strong>22<br \/>\n<strong>replace<\/strong>\u00a0efficient\u00a0<strong>= 0 if\u00a0<\/strong>mpg <strong>&lt;<\/strong> 22<\/td>\n<td style=\"width: 50%;\">Creates a dummy variable that takes on value 1 if the observation has above average gas mileage, and value 0 otherwise. The\u00a0<strong>replace<\/strong> command fills in the missing values that are necessarily generated by the first command. Generally,\u00a0<strong>replace\u00a0<\/strong>is used to modify contents of an existing variable.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><h3 ><a href=\"#modifying-data-6\" >Modifying Data<\/a><\/h3><div id=\"modifying-data-6\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\"><strong>rename\u00a0<\/strong>headroom hdrm<\/td>\n<td style=\"width: 50%;\">Renames an existing variable. We can rename the variable\u00a0<em>headroom\u00a0<\/em>to\u00a0<em>hdrm<\/em> for short.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>drop\u00a0<\/strong>headroom trunk length<\/td>\n<td style=\"width: 50%; height: 24px;\">Removes the variables\u00a0<em>headroom, trunk, and length\u00a0<\/em>from the data file. Note that\u00a0<strong>drop\u00a0<\/strong>(and\u00a0<strong>keep<\/strong>) is irreversible. To retrieve these variables you have to <strong>clear<\/strong> and\u00a0reopen the original data file. (Make sure you always have a copy of the original when you save data files.)<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>keep<\/strong>\u00a0make price mpg rep78 foreign<\/td>\n<td style=\"width: 50%; height: 24px;\">Removes all other variables from the data file, and keeps only the specified variables. Most\u00a0<strong>drop<\/strong> commands can be replaced with\u00a0<strong>keep<\/strong> for this opposite effect.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>drop if\u00a0<\/strong>foreign\u00a0<strong>==\u00a0<\/strong>1<\/td>\n<td style=\"width: 50%; height: 24px;\">Drops all observations that satisfy the specified conditions. Here we want to look only at domestically produced cars, so we\u00a0<strong>drop\u00a0<\/strong>all observations where the <em>foreign<\/em> variable takes on value 1.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>gsort<\/strong>\u00a0<strong>-<\/strong>price<br \/>\n<strong>keep in\u00a0<\/strong>1\/20<\/td>\n<td style=\"width: 50%; height: 24px;\">Sorts the observations in a specified order of a variable, and then keeps the observations in a specified range. First we use\u00a0<strong>gsort\u00a0<\/strong>to arrange the observations in descending (<strong>-<\/strong>)\u00a0order of <em>price<\/em>. Then we\u00a0<strong>keep<\/strong> observations 1 to 20, dropping everything else. The resulting data set represents the observations of the top 20 most expensive cars.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>keep if inrange(<\/strong>mpg<strong>,<\/strong>20<strong>,<\/strong>30<strong>)<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Keeps the observations where the value of a variable lies within a specified range. Here we keep the cars with <em>mpg<\/em> between 20 and 30 (inclusive).<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><b>replace\u00a0<\/b>price <strong>=<\/strong> 4000 <strong>if<\/strong> price <strong>&lt;<\/strong> 4000<\/td>\n<td style=\"width: 50%; height: 24px;\">Replaces values of observations that satisfy certain conditions. Here we replace values of <em>price<\/em> lower than $4,000 with 4000.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>recode<\/strong>\u00a0mpg\u00a0<strong>(<\/strong>12<strong>\/<\/strong>22<strong>=<\/strong>0 <strong>\"<\/strong>Inefficient<strong>\")(<\/strong>23<strong>\/<\/strong>41=1\u00a0<strong>\"<\/strong>Efficient<strong>\"), generate (<\/strong>Efficiency<strong>)<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Recodes and generates a new dummy variable for\u00a0<em>mpg<\/em>. We replace values from 12 to 22 with the value 0 and the label \"Inefficient,\" and follow suit with values from 23 to 41. The\u00a0<strong>generate<\/strong> option here creates a new recoded variable, otherwise the default is to replace the variable\u00a0<em>mpg<\/em>.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>mvdecode _all, mv(<\/strong>9999<strong>)<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Decodes datasets that input the value \"9999\" for missing values. Here we replace <strong>all<\/strong> values of 9999 across all observations and variables with a missing value marker \".\".<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>mvencode\u00a0<\/strong>rep78<strong>, mv(<\/strong>9999<strong>)<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Encodes missing variables in the current dataset to a specified value. Here we replace the missing values (denoted by \".\") in the variable <em>rep78<\/em> with a value of 9999. This is useful for exporting data.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><\/div><!-- #random-accordion-id-335end of accordion shortcode -->\n<h2><\/h2>\n<h2><span style=\"color: #dd3396;\"><em>Commands<\/em>: Regression Analysis <\/span><\/h2>\n<div id=\"random-accordion-id-603\" class=\"accordion-shortcode  \"><h3 ><a href=\"#ols-linear-regression-7\" ><abbr class='c2c-text-hover' title='Ordinary Least Square'>OLS<\/abbr> Linear Regression<\/a><\/h3><div id=\"ols-linear-regression-7\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 161px;\">\n<td style=\"width: 50%; height: 161px;\"><strong>regress\u00a0<\/strong>price mpg foreign rep78<\/td>\n<td style=\"width: 50%; height: 161px;\">Regresses independent variable <em>price <\/em>on dependent variables <em>mpg, <\/em><em>foreign <\/em>and <em>rep78 <\/em>using ordinary least squares linear regression. Generates coefficients, standard errors, p-values , ANOVA table etc.<\/td>\n<\/tr>\n<tr style=\"height: 155px;\">\n<td style=\"width: 50%; height: 155px;\"><strong>regress <\/strong>price mpg foreign rep78,<strong> robust<\/strong><\/td>\n<td style=\"width: 50%; height: 155px;\">Option <strong>robust<\/strong> gives the robust standard errors and t-statistics. Generally <strong>robust<\/strong> is used to adjust for heteroskedasticity, and is usually justifiable with large sample sizes.<\/td>\n<\/tr>\n<tr style=\"height: 150px;\">\n<td style=\"width: 50%; height: 150px;\"><strong>regress <\/strong>price mpg foreign rep78<strong>, noconstant<\/strong><\/td>\n<td style=\"width: 50%; height: 150px;\">Option <strong>noconstant<\/strong> is used when the theoretical model calls for the intercept term to be zero.<\/td>\n<\/tr>\n<tr style=\"height: 90px;\">\n<td style=\"width: 50%; height: 90px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1014\" src=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/04\/regression-1-300x133.png\" alt=\"\" width=\"300\" height=\"133\" srcset=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/04\/regression-1-300x133.png 300w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/04\/regression-1-400x177.png 400w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/04\/regression-1.png 633w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/td>\n<td style=\"width: 50%; height: 90px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/ordinary-least-square-2\/#reg\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results<\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><h3 ><a href=\"#storing-values-after-regressio-8\" >Storing Values (After Regression)<\/a><\/h3><div id=\"storing-values-after-regressio-8\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>sca<\/strong> beta1 = <strong>_b[<\/strong>mpg<strong>]<\/strong><br \/>\n<strong>sca <\/strong>se1 <strong>= _se[<\/strong>mpg<strong>]<\/strong><br \/>\n<strong>sca <\/strong>obs <strong>= <\/strong>74<\/td>\n<td style=\"width: 50%; height: 23px;\">Stores the values for later use. <strong>_b[<\/strong>mpg<strong>]<\/strong> denotes the beta coefficient from the last performed regression - and likewise with the standard error <strong>_se[<\/strong>mpg<strong>]<\/strong>. We can also store numbers such as the number of observations. This tool can be useful for manually calculating test statistics or for keeping track of values after running several regression models.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>di <\/strong>beta1<br \/>\n<strong>di e(r2)<\/strong><\/td>\n<td style=\"width: 50%; height: 23px;\">Displays values in the results window - the capabilities are similar to that of <strong>sca<\/strong>. Here we display the value \"beta1\" which we previously stored, as well as the R-squared of the last performed regression.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>gen <\/strong>beta1 = <strong>_b[<\/strong>mpg<strong>]<\/strong><br \/>\n<strong>label variable <\/strong>beta 1 <strong>\"<\/strong>first specification mpg\"<\/td>\n<td style=\"width: 50%; height: 23px;\">Stores the beta coefficient for mpg as a variable with the label \"first specification mpg.\" This is an alternative to <strong>sca<\/strong> if you need the value for later use if you are testing several model specifications - you can keep track of it in the variable list and give it a fitting label.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>predict yhat<br \/>\n<\/strong><\/td>\n<td style=\"width: 50%;\">Generates a new variable variable <em>yhat <\/em>based on the predicted values for each observation.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div> <h3 ><a href=\"#regression-diagnostics-9\" >Regression Diagnostics<\/a><\/h3><div id=\"regression-diagnostics-9\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Multicollinearity<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>pwcorr<\/strong> mpg foreign rep78<strong>, sig<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Displays pairwise correlations between specified variables. Option <strong>sig<\/strong> displays significance levels for correlations. This is helpful in checking for multicollinearity.<\/td>\n<\/tr>\n<tr style=\"height: 115px;\">\n<td style=\"width: 50%; height: 115px;\"><strong>vif <\/strong><\/td>\n<td style=\"width: 50%; height: 115px;\">Displays the variance inflation factor for each independent variable. A VIF value greater than 10 suggests multicollinearity.<\/td>\n<\/tr>\n<tr style=\"height: 101px;\">\n<td style=\"width: 50%; height: 101px;\">\n<h4><strong>Normality of Residuals<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 101px;\"><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>predict<\/strong> r<strong>, residual<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Generates a new variable <em>r<\/em> based on the residuals of each observation from the linear regression. (See next command)<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>kdensity <\/strong>r<strong>, normal<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Displays a kernel density estimate graph of the variable <em>r<\/em>. Option normal plots this graph against the normal distribution. Normality of the residuals is important for hypothesis testing<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>gladder <\/strong>price<\/td>\n<td style=\"width: 50%; height: 24px;\">Displays several graphs representing different transformations of the variable <em>price<\/em>. Each graph contains a histogram and a kernel density estimate. Normality of variables through choosing the proper functional form can help achieve normality of residuals.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Homoskedasticity<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>rvfplot, yline(0)<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Plots the residuals against the fitted values from the regression. Ideally, for homoskedasticity there should be no discernible pattern in the residuals' variance from the baseline y = 0.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>estat hettest <\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Tests the hypothesis that the errors are homoskedastic. A high chi-squared statistic and a low p-value implies that the errors are heteroskedastic.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Linearity<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 161px;\">\n<td style=\"width: 50%; height: 161px;\"><strong>scatter <\/strong>r mpg<\/td>\n<td style=\"width: 50%; height: 161px;\">Displays a two-way scatterplot of the residuals against mpg. (see <strong>predict<\/strong> to generate residual \"r\"). Plot the residuals against each independent variable and check for non-linear relationships.<\/td>\n<\/tr>\n<tr style=\"height: 230px;\">\n<td style=\"width: 50%; height: 230px;\"><strong>acprplot <\/strong>mpg<strong>, lowess<\/strong><\/td>\n<td style=\"width: 50%; height: 230px;\">Displays an augmented component-plus-residual plot and a <strong>lowess<\/strong> smooth of the plotted points. It shows a scatterplot of all the points, a linear regression line, and a non-linear \"lowess\" curve. The relationship is linear if the lowess curve closely follows the linear regression line.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Omitted Variable Bias<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\"><strong>estat ovtest<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">Tests for omitted variable bias. A high F-statistic and a low p-value implies there may be omitted variable(s).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div>\n<h3 ><a href=\"#regression-with-independent-va-10\" >Regression with Independent Variable being Dummy<\/a><\/h3><div id=\"regression-with-independent-va-10\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Logit Regression<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 115px;\">\n<td style=\"width: 50%; height: 115px;\"><strong>logit<\/strong> foreign weight mpg<\/td>\n<td style=\"width: 50%; height: 115px;\">A logistic regression fits a binary response model given a set of regressors to estimate the probability of a positive outcome. The specific functional form arises from the assumption of a logistic distribution for the error term in the regression. Displays the logs of odds ratios of the regressors.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><strong>logistic <\/strong> foreign weight mpg<\/td>\n<td style=\"width: 50%; height: 73px;\">Displays the odds ratios of the individual regressors.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\">\n<p><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/ordinary-least-square\/#logit\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results for <strong>logit<\/strong><\/span><\/a><\/p>\n<p><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/ordinary-least-square\/#logistic\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results for <strong>logistic<\/strong><\/span><\/a><\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Probit Regression<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 101px;\">\n<td style=\"width: 50%; height: 101px;\"><strong>probit<\/strong> foreign weight mpg<\/td>\n<td style=\"width: 50%; height: 101px;\">A probit regression fits a binary response model by assuming a standard normal distribution instead of the logistic distribution for the probability of a positive outcome.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/ordinary-least-square\/#probit\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results for <strong>probit<\/strong><\/span><\/a><\/td>\n<\/tr>\n<tr style=\"height: 101px;\">\n<td style=\"width: 50%; height: 101px;\">\n<h4><strong>Multinomial Logit Regression<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 101px;\"><\/td>\n<\/tr>\n<tr style=\"height: 150px;\">\n<td style=\"width: 50%; height: 150px;\"><strong>mlogit<\/strong> lab_status sex age education<\/td>\n<td style=\"width: 50%; height: 150px;\">In a multinomial logit model, the number of outcomes that the dependent variable can possibly accommodate is greater than two and whose categories are not ordered in a genuine sense. This is the main difference of the multinomial from the ordinary logit. Displays coefficient of regressors with a randomly chosen base outcome.<\/td>\n<\/tr>\n<tr style=\"height: 115px;\">\n<td style=\"width: 50%; height: 115px;\"><strong>mlogit<\/strong> lab_status sex age education, <strong>base(<\/strong>0<strong>)<\/strong><\/td>\n<td style=\"width: 50%; height: 115px;\">The above command allows <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> to arbitarily choose which outcome to use as the base outcome. If one wants to specify the base outcome, it can be done by adding the base() option.<\/td>\n<\/tr>\n<tr style=\"height: 115px;\">\n<td style=\"width: 50%; height: 115px;\"><strong>mlogit<\/strong> lab_status sex age education, <strong>rrr<\/strong><\/td>\n<td style=\"width: 50%; height: 115px;\">Similar to odds-ratios in a binary-outcome logistic regression, one can tell <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> to report the relative risk ratios (RRRs) instead of the coefficient estimates, it can be done by adding the rrr option.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/ordinary-least-square\/#mlogit\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results for <strong>mlogit<\/strong><\/span><\/a><\/td>\n<\/tr>\n<tr style=\"height: 101px;\">\n<td style=\"width: 50%; height: 101px;\">\n<h4><strong>Ordered Logit Regression<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 101px;\"><\/td>\n<\/tr>\n<tr style=\"height: 101px;\">\n<td style=\"width: 50%; height: 101px;\"><strong>ologit<\/strong> v201 daughter_son_ratio v133 v012 poorest poorer middle richer<\/td>\n<td style=\"width: 50%; height: 101px;\">In an ordered logit model the actual values taken on by the categorical dependent variable are irrelevant, except that larger values are assumed to correspond to \u2018higher\u2019 outcomes. Displays log odds of regressors.<\/td>\n<\/tr>\n<tr style=\"height: 101px;\">\n<td style=\"width: 50%; height: 101px;\"><strong>ologit<\/strong> v201 daughter_son_ratio v133 v012 poorest poorer middle richer, <strong>or<\/strong><\/td>\n<td style=\"width: 50%; height: 101px;\">To, obtain the odds ratio instead of the log odds, we need to use the or option.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/ordinary-least-square\/#ologit\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results for <strong>ologit<\/strong><\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><h3 ><a href=\"#regression-with-count-variable-11\" >Regression with Count variable<\/a><\/h3><div id=\"regression-with-count-variable-11\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Poisson Regression<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 115px;\">\n<td style=\"width: 50%; height: 115px;\"><strong>poisson<\/strong> y x, <strong>exposure(<\/strong> e <strong>) <\/strong><\/td>\n<td style=\"width: 50%; height: 115px;\">Poisson regression fits models of the number of occurrences (counts) of an event where it is assumed that the number of occurrences follow a Poisson distribution. y is the dependent variable, x is the independent variable and e is exposure or the expected number of observed events.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><strong>poisson<\/strong> y x, <strong>exposure(<\/strong> e <strong>) irr <\/strong><\/td>\n<td style=\"width: 50%; height: 73px;\">This option irr tells <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> to report the incidence-rate ratios.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><strong>estat gof<\/strong><\/td>\n<td style=\"width: 50%; height: 73px;\">Test whether the Poisson regression or Negative binomial model is appropriate.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/poisson-regression-2\/#poisson\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results for poisson<\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Negative Binomial Regression<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 115px;\">\n<td style=\"width: 50%; height: 115px;\"><strong>nbreg<\/strong> y x, <strong>offset(<\/strong> e <strong>) <\/strong><\/td>\n<td style=\"width: 50%; height: 115px;\">In a Negative Binomial regression the dependent count variable is believed to be generated by a Poisson-like process, except that the variation is greater than that of a true Poisson. y is the dependent variable, x is the independent variable and e is exposure or the expected number of observed events.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><strong>nbreg<\/strong> y x, <strong>offset(<\/strong> e <strong>) lnalpha( <\/strong> <strong> z) <\/strong><\/td>\n<td style=\"width: 50%; height: 73px;\">This option tells <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> to model the overdispersion parameter as a linear combination of the observable variable z.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><strong>nbreg<\/strong> y x, <strong>offset(<\/strong> e <strong>) dispersion(constant) <\/strong><\/td>\n<td style=\"width: 50%; height: 73px;\">This option tells <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> to have a constant dispersion across all observations.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/poisson-regression-2\/#nbreg\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results for nbreg<\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\">\n<h4><strong>Zero Negative Binomial Regression<\/strong><\/h4>\n<\/td>\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<\/tr>\n<tr style=\"height: 115px;\">\n<td style=\"width: 50%; height: 115px;\"><strong>zinb<\/strong> y x, <strong>inflate(<\/strong> z <strong>) vuong zip<\/strong><\/td>\n<td style=\"width: 50%; height: 115px;\">In a Zero Negative Binomial regression the dependent count variable the count of zeros is much larger than the count of any other frequency. y is the dependent variable, x is the independent variable and z is used as a regressor to explain the reason for such excess or inflated zeros.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/poisson-regression-2\/#zinb\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #dd3396;\">Interpreting results for zinb<\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div> <h3 ><a href=\"#instrumental-variable-regressi-12\" >Instrumental Variable Regression<\/a><\/h3><div id=\"instrumental-variable-regressi-12\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 161px;\">\n<td style=\"width: 50%; height: 161px;\"><strong>ivregress\u00a02sls <\/strong> y x1 (x2 = z1)<\/td>\n<td style=\"width: 50%; height: 161px;\"><abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>Stata<\/abbr> executes a two-stage least square where y is the dependent variable, x1 is an exogenous explanatory variable, x2 is the endogenous explanatory variable which is being instrumented by the variables z1.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/instrumental-variable-regression\/\"><span style=\"color: #dd3396;\">Examples and more explanation<\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div> <h3 ><a href=\"#difference-in-difference-regre-13\" >Difference-in-Difference Regression<\/a><\/h3><div id=\"difference-in-difference-regre-13\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 161px;\">\n<td style=\"width: 50%; height: 161px;\"><strong>reg <\/strong> y treatment time treatment#time<\/td>\n<td style=\"width: 50%; height: 161px;\">y is the dependent variable, treatment is a dummy variable with value 1 for treated group and 0 for control group, time is a dummy variable with value 1 when treatment started and 0 before treatment and the interaction between time and treatment captures the difference in difference coefficient.<\/td>\n<\/tr>\n<tr style=\"height: 73px;\">\n<td style=\"width: 50%; height: 73px;\"><\/td>\n<td style=\"width: 50%; height: 73px;\"><a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/difference-in-difference-regression\/\"><span style=\"color: #dd3396;\">Examples and more explanation<\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><\/div><!-- #random-accordion-id-603end of accordion shortcode -->\n<h2><\/h2>\n<h2><span style=\"color: #dd3396;\"><em>Commands<\/em>: Displaying Regression Results <\/span><\/h2>\n<p><div id=\"random-accordion-id-548\" class=\"accordion-shortcode  \"> <h3 ><a href=\"#generating-regression-table-14\" >Generating Regression Table<\/a><\/h3><div id=\"generating-regression-table-14\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>ssc install estout<\/strong><\/td>\n<td style=\"width: 50%; height: 23px;\">Installs a program that generates regression tables, see following commands for use.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>eststo <\/strong>spec1<\/td>\n<td style=\"width: 50%; height: 23px;\">Stores the last performed regression as one of the model specifications - spec1 - to be displayed in the table<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>esttab using <\/strong>AutoRegTable.smcl<strong>, se title (<\/strong>1978 Auto Analysis<strong>)<\/strong><\/td>\n<td style=\"width: 50%;\">Exports a regression table with <strong>title<\/strong> \"1978 Auto Analysis\" comprised of all specifications previously stored with <strong>eststo<\/strong> command to the <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>Stata<\/abbr> file \"AutoRegTable.smcl\". Displays beta coefficients, standard errors (through option <strong>se<\/strong>), and significance stars.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>translate <\/strong>AutoRegTable.smcl AutoRegTable.pdf<\/td>\n<td style=\"width: 50%;\">Converts the auto analysis regression table from a <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>Stata<\/abbr> file to a PDF file.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<\/div><h3 ><a href=\"#common-graphs-15\" >Common Graphs<\/a><\/h3><div id=\"common-graphs-15\" class=\"accordian-shortcode-content \" ><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\"><strong>histogram\u00a0<\/strong>mpg<strong>,\u00a0bin(<\/strong>10<strong>)<br \/>\n<\/strong><\/td>\n<td style=\"width: 50%;\">Displays a histogram of <em>mpg\u00a0<\/em>with parameters decided by <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr>. Option\u00a0<strong>bin(<\/strong>10<strong>)<\/strong> specifies number of bins. Width of each bin determined automatically by bin size and range of\u00a0<em>mpg.<\/em><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>scatter\u00a0<\/strong>price mpg\u00a0<strong>|| lfit\u00a0<\/strong>price mpg<strong><br \/>\n<\/strong><\/td>\n<td style=\"width: 50%;\">Displays a two-way scatterplot of variables <em>price\u00a0<\/em>and\u00a0<em>mpg.\u00a0<\/em>\"||\" Allows us to overlay another graph on top - in this case, we overlay a line of best fit using option\u00a0<strong>lfit<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\"><strong>graph matrix\u00a0<\/strong>weight length mpg<strong>, half<br \/>\n<\/strong><\/td>\n<td style=\"width: 50%;\">Displays scatterplots of every pairwise combination of variables. Option\u00a0<strong>half<\/strong> omits the same graphs with reversed order.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>kdensity\u00a0<\/strong>price<strong>, normal<\/strong><\/td>\n<td style=\"width: 50%; height: 23px;\">Displays a kernel density estimate of the variable <em>price<\/em>\u00a0- a smoothed histogram essentially. Option <strong>normal<\/strong> plots the graph against the normal distribution for comparison.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>graph bar\u00a0<\/strong>price<strong>, over(<\/strong>rep78<strong>)<\/strong><\/td>\n<td style=\"width: 50%; height: 23px;\">Displays a bar graph of the mean values for <em>price<\/em> for each value of\u00a0<em>rep78<\/em>. This is helpful when the independent variable is continuous and the dependent variable is categorical.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>graph hbox\u00a0<\/strong>mpg<strong>, by(foreign)<\/strong><\/td>\n<td style=\"width: 50%; height: 23px;\">Displays a box and whisker plot of the variable\u00a0<em>mpg<\/em>. This represents the five number summary of the variable as well as outside values. Option\u00a0<strong>by(foreign)\u00a0<\/strong>generates two separate graphs representing <em>mpg<\/em> for foreign cars and for domestic cars.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>gladder\u00a0<\/strong>price<\/td>\n<td style=\"width: 50%; height: 23px;\">Displays several graphs representing different transformations of the variable\u00a0<em>price<\/em>. Each graph contains a histogram and a kernel density estimate.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>correlate\u00a0<\/strong>mpg weight price<\/td>\n<td style=\"width: 50%; height: 23px;\">Displays a correlation matrix for all specified variables.<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 50%; height: 23px;\"><strong>graph export\u00a0<\/strong>PriceMpgScatter.pdf<\/td>\n<td style=\"width: 50%; height: 23px;\">Exports the graph currently displayed in the graph window as a PDF file titled \"PriceMpgScatter\".<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #444444;\"><\/p>\n<\/div><\/div><!-- #random-accordion-id-548end of accordion shortcode --><\/span><\/p>\n<p>NOTE: This is not an exhaustive list of each command&#8217;s potential. For more options in <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> type &#8220;<strong>help&#8221;\u00a0<\/strong>followed by the name of the command. You can also type &#8220;<strong>search<\/strong>&#8221; followed by a statistical term to find the exact command for that operation. You can replicate and explore these commands further by navigating the appropriate menus in the taskbar.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>These are simple examples of useful commands and options using 1978 auto data from <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr>. The commands are in\u00a0bold text;\u00a0variables and other inputs are in plain text for the sake of example. Commands: SET UP Commands: Data Management &amp; Analysis &hellip; <a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/stata\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":59154,"featured_media":0,"parent":2,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-26","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/users\/59154"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":127,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages\/26\/revisions"}],"predecessor-version":[{"id":1286,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages\/26\/revisions\/1286"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/media?parent=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}