NA310G Applied econometrics in Stata

Help desk

Drop in with your do-file and your question. No booking needed.

The help desk is the fastest way to get unstuck: bring your laptop, the do-file and the log, and the exact error message or the number you do not understand.

Date Time Where
Fri 23 Oct 09:00–10:00 N4008 (Nova House)
Mon 26 Oct 15:00–17:00 N4008
Tue 27 Oct 09:00–10:00 and 15:00–16:00 N4008
Wed 28 Oct 15:00–16:00 N4008
Thu 29 Oct 09:00–10:00 and 15:00–16:00 N4008
Fri 30 Oct 09:00–11:00 and 13:00–16:00 N4008
Mon 2 – Fri 6 Nov 09:00–10:00 daily Zoom (link on Blackboard)

Rooms can change at short notice; if so, it is announced on Blackboard. Lab 3 (Wed 28 Oct, 09:15–15:00, F103) is mostly help in the room after a short lab lecture.

From the lab folder to your report

You build the report in a copy of your lab folder, with the same structure and the same key steps as the labs: the same do-files, in the same order, edited to fit your own question. You do not start from scratch, and you do not add new files next to the lab’s. The lab do-files are a model, not the answer: they show how; the instructions say what your report must do, and they ask for more than the lab demo did (see step 3).

1. Copy. Make a copy of the whole project folder (Mac: select it and press Cmd+D; Windows: copy and paste) and rename the copy na310g-<your code>. Leave the lab folder as it is, to look back at.

Name your do-files with your code, never your name. In the copy, add your personal code at the end of each do-file’s name: 2_sample_vars.do becomes 2_sample_vars_K7Q2MX.do. Then you can have the lab’s do-file and your own open side by side and always see which is which. Change the do lines in master.do to the new names, or it stops with “file not found”.

2. Clear out the labs, in the copy. Delete:

Keep master.do, the folder dofiles, README and report_checklist.

3. Adapt each do-file to your question, and do what the instructions ask, not only what the lab did:

4. The occupation file is optional. Your research question needs no merge: your outcome, ai_firm and the required controls are all in your own dataset. You need na310g_occupations_ssyk2012.dta only if you use an occupation variable, for example as an instrument (for a VG). If you do not, delete block B4 (the merge) in 2_sample_vars.do, block G in 5_tests_iv.do, and the occupation file in data/raw.

5. Run everything from the copy. Close Stata, then double-click the copy’s master.do: it sets $root to the folder Stata opens in, so if Stata is still open from the lab folder, your files write there. master.do must run from top to bottom without an error. Its log, with the verification line, goes in your appendix.

Getting the most out of it

  1. Run your do-file from the top first. Many problems disappear when the file runs in one go.
  2. Bring the smallest piece of code that shows the problem, and the error message.
  3. Say what you expected to see before you ran it. That is usually where the misunderstanding is.

Common questions

Where do I work on my report, so I do not overwrite the lab files? In a copy of the lab folder, made and cleaned as in From the lab folder to your report above.

Professional services is J + K + M. Does the lab’s grouping include M (divisions 69–75)? Yes. The line in 2_sample_vars.do reads inrange(division, 58, 66) | inrange(division, 69, 75); | means “or”, so it covers J and K (58–66) and M (69–75). Use it as it is.

Should I drop the firms outside my industry and geography, and when? Your sample is your industry and your geography. Section 4 of the report asks for the selection step by step, from the original N to your final N, so ask yourself at each step: how many observations go, and why? And which firm-years will silently drop out of the regression later?

A variable I want to log has negative or zero values. What do I do? The brief asks you to decide, report how many firm-years it concerns, and say why; there is no single right answer. Questions to ask yourself: what does a negative value mean in the accounts? Which firms would you lose, and would losing them change what your sample represents? How skewed is the variable? Would your conclusion change with the other choice? And for a control: is it built from the same accounts as your outcome?

My outcome is a ratio, such as vacancies per employee. Can I add its denominator (employees) as a control? Ask yourself first: if employees is high in one year by chance or by a recording error, what happens to your outcome that year? What relation between the two would you then find even if size had no effect at all? And why does the brief measure firm size by net sales for this outcome, but by employees for the others? If you still add it, show the model with and without it.

How do I get the correlation matrix into Word as a table? The lab’s pwcorr (do-file 3, B7) writes only to the log. Add this after B7, with your own variables in place of the lab’s:

correlate ln_fin ln_emp ln_cap ai_firm
matrix C = r(C)
putdocx clear
putdocx begin
putdocx paragraph
putdocx text ("Table 3. Correlations")
putdocx table corr = matrix(C), rownames colnames nformat(%9.2f)
putdocx save "$root/output/tables/correlations.docx", replace

correlate uses the same observations for every variable, as your regression does. In Word, replace the variable names with labels and add a note below the table.

My regression table shows the number of observations but not the number of firms. Is that a problem? No. Give the number of firms in the note under the table (“N = … firm-years, … firms, 2018–2024”), as the example report does. If you want a row instead, in E5 of 4_regressions.do: add e(N_clust) to the pooled-OLS collect line and e(N_g) to the FE and RE lines; add the line collect recode result N_clust = N_g; add N_g "Firms" to collect label levels result; and write N_g after N in collect style cell result[N] and in collect layout.