Stat 3500: Stas' section

Most of information is posted on the blackboard. The data and the resutls for Stata assignments are posted here.

The textbook data are available here.

Assignment test0: basics of Stata, summarizing the data. Assignment text and John Doe's example, preliminary results.

Assignment test1: statistical distributions in Stata. Assignment text and John Doe's example, preliminary results.

Assignment test2: confidence intervals and hypothesis testing. Assignment text and John Doe's example, preliminary results.

Assignment test3: ANOVA. Assignment text and John Doe's example, preliminary results.

Assignment midterm1: The first midterm, Stata component. Assignment text (no John Doe's example), preliminary results, backbone do-file.

Assignment test4: regression. Assignment text and John Doe's do-file, preliminary results.

Assignment midterm2: The second midterm, Stata component. Assignment text (no John Doe's example), preliminary results.

Assignment test5: Multiple regression. Assignment text and John Doe's example, preliminary results.

Assignment test6: Multiple regression and diagnostics. Assignment text and John Doe's example, preliminary results.

Assignment midterm3: The second midterm, Stata component. Assignment text, first attempt results.


Stata do-files

Ch. 16 do-file

Frequently Asked Questions.

1. I entered the same question twice. How do I fix this?

One possible way is to postclose your current file, and start everything over again. Make sure you have specified replace option in the post command, then. You can click on the commands in the Command window to quickly recall and repeat them.

Another way is to continue and finish your file, and then edit it. Suppose in test0 assignment, John Doe entered question 3 twice (and made an error the first time), so that his resulting file looks like this:
. list

     +-------------------+
     | Question   Answer |
     |-------------------|
  1. |        1       15 |
  2. |        2       12 |
  3. |        3        0 |
  4. |        3     .004 |
  5. |        4    2.574 |
     |-------------------|
  6. |        5     .853 |
     +-------------------+

.
The line number 3 is the wrong one, and needs to be deleted. This can be achieved with drop Stata command:
. drop in 3
(1 observation deleted)

. list

     +-------------------+
     | Question   Answer |
     |-------------------|
  1. |        1       15 |
  2. |        2       12 |
  3. |        3     .004 |
  4. |        4    2.574 |
  5. |        5     .853 |
     +-------------------+

. 
Now this file is OK, but it is only in Stata memory. It needs to be saved back to disk before upload. Note replace option that is necessary for the file to be overwritten:
. save answers-test0-99999.dta, replace
file answers-test0-99999.dta saved

. 
2. I entered a wrong answer! What do I do?

See FAQ1. You can just type the correct answer, and edit the resulting file.

3. I skipped a question! Do I need to start over again?

No, the order of questions does not matter. You can add whatever you've missed at any time, just make sure you don't have it doubled. (See FAQ #1 about what to do about it.) If you want to, you can sort your data later.

Suppose John Doe answered some questions on test0 out of order, so his final file looks like this:
. list

     +-------------------+
     | Question   Answer |
     |-------------------|
  1. |        1       15 |
  2. |        2       12 |
  3. |        4    2.574 |
  4. |        5     .853 |
  5. |        3     .004 |
     +-------------------+

. 
The perfectionist order can be restored as follows:
. sort Question

. list

     +-------------------+
     | Question   Answer |
     |-------------------|
  1. |        1       15 |
  2. |        2       12 |
  3. |        3     .004 |
  4. |        4    2.574 |
  5. |        5     .853 |
     +-------------------+
. save answers-test0-99999.dta, replace
file answers-test0-99999.dta saved

. 
John Doe saved his file, so that in the future the observations are logically ordered by Question variable.

Note that in general the order of observations might be important. However the grading engine of Stata takes care of it automatically.


Stata tricks and tips.

Tip #1

Stas suggested attempting the midterm twice and comapring the answers. Here's how you can use Stata to automate this comparison. Suppose you have two files, take1.dta and take2.dta that contain the two attempts, with variables Question and Answer in each of them. Run the following sequence:
. use take1, clear

. merge Question using take2.dta , sort update

. tab _merge

. list if _merge != 3

.
Stata command merge combines several data sets. It leaves behind the variable _merge that contains the resulting codes to show how observations from different files were combined. The value of 3 indicates perfect match. Other values indicate problems.

Tip #2

If you have your dta file but did not care to produce a do-file, here's a quick fix using an alternative way to enter your Question and Answer data.
  1. Open a do-file editor (or emacs, or Word, or whatever your favorite editor might be, but make sure to save your result as plain text with .do extension).
  2. Type four lines:
    clear
    input Question Answer
    end
    save answers-midterm3-######
    
  3. Load and list your results as follows
    use answers-midterm3-######, clear
    list , clean noobs noheader
    
    This will produce a listing with the values only.
  4. Copy and paste that listing between the input and end lines of your skeleton do-file.
This will quickly recreate your submission as a do-file.