Stata programming is not difficult since it mainly involves the use of Stata commands to you already use. The trick to Stata programming is to use the appropriate commands in the right sequence. Of course, this is the trick to any kind of programming. There are two kinds of files that are used in Stata programming, do-files and ado-files.
If you wanted to cluster by year, then the cluster variable would be the year variable. If you wanted to cluster by industry and year, you would need to create a variable which had a unique value for each industry-year pair.
To allow observations which share an industry or share a year to be correlated, you need to cluster by two dimensions industry and year. For most estimation commands such as logits and probits, the previous form of the command will also work.
For example, to run a logit with clustered standard errors you would use the command: Papers by Thompson and by Cameron, Gelbach and Miller suggest a way to account for multiple dimensions at the same time.
This approach allows for correlations among different firms in the same year and different years in the same firm, for example. See their papers and mine for more details and caveats. I have written a Stata ado file to implement this estimation procedure. It runs a regression and calculates standard errors which account for two dimensions of within cluster correlation.
The variables which record the two dimensions e. There are also versions of the Stata ado file that estimates logit logit2. The format is similar to the cluster2.
In this case, instead of subtracting off the White variance matrix, you need to subtract off the variance matrix clustered by firm-year i.
The program has been modified to automatically check for this condition and use the correct third matrix. The program is also now compatible with the outreg procedure. The code for estimating clustered standard errors in two dimensions using R is available here.
Fama-MacBeth Standard Errors Stata does not contain a routine for estimating the coefficients and standard errors by Fama-MacBeth that I know ofbut I have written an ado file which you can download.
The ado file fm. The program allows you to specify a by variable for Fama-MacBeth. Thus if in stead of running T cross-sectional regressions, you could run N time series regressions by specifying the firm identifier as the byfm variable.
If the option is not specified, it uses the time variable as set by the tsset comment as the by variable.
The form of the command is: This tells Stata the name of the firm identifier and the time variable.To install an ado file, type "ssc install xxx" (where xxx should be replaced with the name of the ado file) in your Stata interactive session.
DO FILES Making do-files is essential because it allows other researchers to replicate your empirical analysis. I'm currently writing a little Stata program in attheheels.com file.
Within attheheels.com file I want to use Mata in order to use the optimize() functions.
When I type end in order to exit MATA, attheheels.com file reads this as the end of the program (I think). but in this case no package with the name attheheels.com (and none even with the name file) exists at SSC at this writing, so no surprise there.
If you didn't literally type attheheels.com then we can only guess wildly at what you did type, but in general it is as said package names (which won't attheheels.com as suffix) and not filenames that need to be typed.
Almost . Ado-files, on the other hand, work like ordinary Stata commands by just using the file name in the command line, for example, median3 read write math science In fact, many of the built-in Stata commands are just ado-files.
Webopedia's list of Data File Formats and File Extensions makes it easy to look through thousands of extensions and file formats to find what you need.
Oct 01, · Typically, you'll want to use an ado file for distribution which would facilitate defining programs (e.g., functions or procedures in other languages) and will allow the file to both define and execute the program; for example, if you define a program in the do file that you wanted to expose to the end user, you would first need to run the.