1、A Brief Introduction to Stata(1),1. Getting Started,1.1 Starting STATA1.2 Running Stata1.3 Open and Save Datasets in Stata1.4 Exiting STATA1.5 Getting help and information 1.6 Notes on STATA Commands 1.7. Entering Data into STATA,1.1 Starting STATA,Start a STATA session by performing either of the f
2、ollowing three procedures: double-click the STATA icon in your desktop. find the STAR button .Use Windows Explorer to navigate across the STATA8 folder and find the button of the executable file named wsestata. Double click on this button.,STATA的用户界面,已执行过的命令窗口,变量窗口,结果输出窗口,STATA windows,Stata Command
3、Stata ResultsReviewVariables,1.2 Running Stata,A command may be typed in the Stata Command window and executed by press the Enter key.Stata running can be interrupted by holding down Ctrl and pressing Pause/Break key.,It is good to open a log_file, press the button or use .log using filename. When y
4、ou want to close the file,use .log close.Append onto the end of the current log. Type .log using myses, append. Discard the old log and replace it with the new one. Type .log using myses, replace. The first choice is probably the best.,You can find out what directory youre in by typing . pwd F:Stata
5、Stuff If you wanted to make a dirctory on the F drive using Stata, type: . cd F: F:,Do-file,Do-file editorRunning do-fileButtonDo dofile,Data editor,Data BrowserData EditorRows represent obserbvation.Columns represent variables.,1.3 Open and Save Datasets in Stata,Stata has its own data format with
6、default extension .dta .,Open a data file,If the file is in the current directory, .Use filenameIf the data are not stored in the current directory,.use c:userdataOr.use c:userdata,clearIn the first form, use filename says to load the data, but Stata will refuse if (1) there is something in memory a
7、nd (2) that something has not been saved on disk.,If the memory allocated to STATA (which is 1,000K or 1M by default) is too little for the data file to be opened we will see an error message like the following: . use hhno room to add more observationsr(901); The following commands allocate 30M to S
8、TATA and then tries again to open the file: . set memory 30m. use hhIf you continue to get an error message, you can try 40m or 50m.,Another important thing to remember is that the memory allocation command (set memory 30m for example) works only if no data set is open. Otherwise you will get follow
9、ing error message: .use hh.set memory 30mno; data in memory would be lostr(4); You can clear the memory using one of the two commands: clear or drop _all.,Save a data file,To save, type: . save 1998Data . save 1998Data, replace . Save,replaceWithout the replace option, the file must not already exis
10、t. If it does, Stata will refuse to overwrite it. With the replace option, the file may exist or not. If the file does exist, it will be overwritten.,.cd c:userdata.use bank .save bank,1.4 Exiting STATA,Stata may be exited in three ways:Click into the Close buttonSelect the File menu from the menu b
11、ar and select ExitType. Exit or . exit, clear in the Stata command windows and press return.,if you have an unsaved data set open, STATA will issue the following error message:. exitno; data in memory would be lostr(4); To remedy this problem you can save the data file and then issue the exit comman
12、d. If you really want to exit STATA without saving the data file:. exit, clear,1.5 Getting help and information,Statas help system consists of two commands: 1) .help 2) .searchYou use help when you know the name of the Stata command on which you want information. This command only works if you type
13、the full command name or keyword unabbreviated.,If you can not recall the full command name or keyword, or you are not sure about which command you want you can use the command lookup or search followed by the command name or keyword. . search mem The STATA website (http: /www.stata. com) has excell
14、ent help facilities, for example, Online Tutorial, Frequently Asked Questions (FAQ), etc.,1.6 Notes on STATA Commands,STATA commands are typed in lower case.All names, including commands or variable names, can be abbreviated as long as there is no ambiguity. e.g. .describe.des,To display the previou
15、s command in Stata Command window, you can press Page-Up key. You can keep doing that until the first command of the session appears. Similarly, the Page-Down key displays the command that follows the currently displayed command in the Stata Command window.,1.7. Entering Data into STATA,the simplest
16、 way is to enter data directly into STATAs spreadsheet-like Data Editor window.The nineth button. edit Note that data from spreadsheets can also be copied and pasted into the Editor.,you can entering data variable-by-variable with the TAB key; or observation-by-observation with the ENTER key. a miss
17、ing value is coded as a period “.”numerical values should not include commas; otherwise STATA considered these values as string.,string variable values can nearly be almost any combination of letters, numbers, and symbols up to 80 characters in length for Intercooled/ Small and up to 244 characters
18、in length for STATA/SE.http:/www.ats.ucla.edu/stat/stata/how_to_get_stata.htmvariable names can be changed by double clicking anywhere in the variables column resulting in a dialogue box. It is suggested that variable names should have 8 characters.,Reading different types of datafile,Using Stata tr
19、ansferOther ways read data into STATA from ASCII files and worksheets, We can use the infile command . cd c:intropovdata. infile domain hcn age using try.txt,use the infix command . clear. infix domain 1 hcn 2 age 3-4 using try2.txtExcel worksheets such as the .xls file can also be read into STATA.
20、However, we have to first read the file with Excel, and convert the file into a comma-delimited file, i.e., click on File, Save AS, and choose as file type CSV. Then, enter . insheet using filename.csv, clear,Review,Ctrl + Pause/Break.log using myses, append. pwd. cd F:use c:userdata,clearset memory 30m. save 1998Data, replace . Save,replace,. exit.help.search.describe.des.edit.infile.infix.insheet,