STATA Replicatio Basu et. Al: the .Di-File
Grade: 8/10
- Basic Commands + .Do-fle
Introduction:
S A A is a statstcal pronram comparable to SPSS. However, S A A can run sinnifcantly more
observatons and variables than SPSS at the same tme. n order to work with S A A you must
understand how the basics work. he basics and basic commands are explained, the second part will
be the Basu Replicaton.
1.1 Stata:
When workinn with Stata you will predominantly use two thinns:
- The primpt paoel: he larne panel in the botom middle, this is where you will be enterinn
your commands
- The di.fle: Which can be accessed throunh the .do fle editor ( )
NOTE: yiu cao access aod edit yiur data usiog ( ) this hiwever is disciuraged wheo diiog
research!
he do-fle editor is similar to windows notepad. encourane you to use it as it makes empirical
analysis much faster. For example, you could open the .do fle, copy-paste the code into the
command window of a diferent data set and run it (provided that the data set has the same
variables!, otherwise it will not work!).
1.2 BASIC Cimmaods:
NO E: Watch out with usinn CAP AL CHARAC ERS as some code will not run properly if capital
numbers are used!
Generate variables
Use the geo command
Example: nen lanprice = prccd[_n-1]
A new variable is created by usinn observatons from a diferent variable column. his can also be
useful to intenrate formulas (e.n. see returns in the .do fle).
Drop observatons
Use the drip if command to delete observatons.
Example: drop if fyear<12 Drop all observatons if year < 12 months
You can use it to drop missinn observatons as well! For this you’ll use drip if missiog (variable
oame). All missinn observatons will be deleted within 1 variable column.
Sortnn data
Use the sirt command.
Example: sort isin datadate All S N codes are sorted by date!
Summarize data in statstcal table
Use the summarize command to make a statstcal table with all basic values such as averane.
Example: summarize wret wpps weps Summarized variables wret, wpps and weps.
Runninn a renression
Use the regress command.
Example: renress depvar dummywret wret dummywret##c.wret
n order to create an interacton put ##c. between two variables (or nenerate a new interacton
variable).