background preloader

Stata

Facebook Twitter

Scatter Plot Matrix in R. Data from Excel to Stata, take two | The Stata Things. The Stata Things. Stata and Excel help: Descriptive statistics « Economystery. Exporting matrix from Stata 12 to Excel or Matlab. Stata Programming Essentials. Ever needed to do the same thing to ten different variables and wished that you didn't have to write it out ten times?

If so, then this article is for you. If not, someday you will—so you might as well keep reading anyway. Stata has all the tools required to write very sophisticated programs, but knowing just a few of them allows you to make everyday do files shorter and more efficient. This article will focus on those programming tools that, in our experience, anyone who uses Stata heavily will eventually want to learn. To benefit from this article you'll need a solid understanding of basic Stata syntax, such as you can get from our Stata for Researchers series. The primary intended audience is Stata users with no other programming experience. This article is best read at the computer with Stata running. Macros A Stata macro is a box you put text in. The macros we'll use are "local" macros. The command to define a local macro is: local name table For example: local x 1 display `x' display 1.

In Stata, how do I store the descriptive statistics of a variable in a macro. In Stata, the .tabstat command computes aggregate statistics of variables such as mean and standard deviation, and its save option stores these statistics in a matrix. For example, to get the N, mean, and standard deviation of personal income, enter: . tabstat income, stat(n mean sd) save The stat() option specifies the aggregate statistics to be computed. N (the number of valid observations), mean, and standard deviation are stored in a matrix r(StatTotal). . matrix stats=r(StatTotal) Finally, to convert a scalar, for example, the mean of the variable, into a macro, enter: . local avg=stats[2,1] If you want to save the matrix as a variable, enter the .svmat command instead: . clear . svmat stats, name(var) You may clear memory before converting the matrix. If you have questions about using statistical and mathematical software at Indiana University, email UITS Research Analytics (formerly known as the Stat/Math Center).

In Stata, how do I save outputs in an external file. Stata can store the outputs and/or the history of typed commmands using the .log and .cmdlog commands. While .log captures both commands and output, the .cmdlog command stores the stream of executed commands only. Suppose you wish to save all commands and output into a text file called myoutput.txt in the c:\temp directory. The first step is to open a log file and begin storing, using the .log using command: . log using c:\temp\myoutput.txt, text replace The text option above writes the log file in ASCII format; the default is the SMCL (Stata Markup and Control Language) format.

To stop saving the log and close the file, enter: . log close To save the commands only, use the .cmdlog command: . cmdlog using c:\temp\mycommand.txt, append To close the file, enter: . cmdlog close Note: Be aware that the .cmdlog using command always saves the log in ASCII format. You may suspend logging using either .log off or .cmdlog off . Stata Library: Graph Examples. Welcome to the Institute for Digital Research and Education Institute for Digital Research and Education Home Help the Stat Consulting Group by giving a gift Stata LibraryGraph Examples Stata 8 has a whole new look for the graphs it produces, as illustrated in the graphs below. You can click on any of the images and a new browser window will open showing the code that produced the graph along with a larger version of the image.

This page was adapted from a page from the Stata Corporation web site and is provided on our site courtesy of, and copyright Stata Corporation. How to cite this page Report an error on this page or leave a comment The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California. IDRE Research Technology Group High Performance Computing Statistical Computing GIS and Visualization BESbswyBESbswy. Stata Graphs - Examples. Gray Calhoun. I'm Gray Calhoun, an Assistant Professor in the Economics Department at Iowa State. I work on Econometric theory, especially time series and applications to forecasting and forecast evaluation. I graduated with a PhD from UC San Diego in 2009, where I worked with Graham Elliott and Allan Timmermann. This page has research and teaching links. Everything else is at my blog, or at the Econometrics Free Library Project (a free textbook development project that you should contribute to).

Email: gcalhoun at iastate dot edu (university) and gray at clhn dot co [sic] (all other email and IM)Office: 467 Heady Hall, (515) 294-6271. Course pages Working papers Other short documents Publications Hypothesis testing in linear regression when k/n is large. Home. Alexander C. Lembcke.