1 Getting Started with Stata 1- WELCOME TO STATA So you've decided you want to learn how to use Stata. Great! Whether you're a completely new user to statistical software, or you've been using other packages, we're sure this survival manual will be able to help you with many of the questions you're bound to have. You've probably come across Stata because your university or employer uses it. Stata has been less popular than us market competitors, such as SPSS and SAS, but is gaining in popularity every year. Stata is now used by medical researchers, biostatisticians, epidemiologists, economists, sociologists, political scientists, geographers, psychologists, social scientists, and other research professionals needing to analyse statistical data. One reason for this is that this software is particularly user-friendly when it comes to analysing complicated data sets, such as those where several data files need to be linked together. The first version of Stata was released over twenty years ago in 1985. Since then, Stata has changed and developed according to user requests. Like its competitors, Stata is used for analysing quantitative data; but, unlike its competitors, Stata has several features which make it stand out as considerably more desirable. What are these reasons? They will be covered throughout this manual, but we will first turn to some of the resources that are available to Stata users. There are considerable resources out there, in addition to this survival manual, to answer questions you might have about Stata. ft should be noted that only a minority of these resources are RESOURCES Getting Started with Stata officially tied to StataCorp (the corporation that creates, sells, and jf!' distributes the Stata software, along with orher products). Stata website If you go to vvww.stala.com you will find yourself at the official StataCorp website. On this site, there is information about StataCorp products, Stata technical support, versions of Stata, and what's new in Stata 'news'. Stata 'news* covers a wide range of topics, including (but not limited to) Stata user group meetings, training courses (such as the ones we teach), publications, and technical updates. Timbertake website Another useful website is www.timberiake.co.uk. Timberiake Consultants is a statistical consultancy company that also distributes and sells Stata in the UK. They have a lot of information on Stata on their website, and this is another place to go if you are looking for conferences and specialized training courses. UCLA Stata 'portal" The University of California at Cos Angeles has a remarkable web 'porta!' at hrrp7/statcoinp,ats.ticla.edu/staLa/ which anyone can access. This site is a virtual 'help desk' for statistical and Stata questions that is provided free of charge by the UCLA Academic Technology Service Stata Consulting Group, it is a remarkably rich resource archiving course notes, tutorials, and detailed annotated examples which include Stata commands, the output, and discussion about what the output means. We explicitly draw on some of these resources in Chanter 8. Stata list Another resource is Statalist, which is a mass subscriber based email list. You can sign up for it by going to www.hspii.harvard, edu/statalist and following the instructions. You should note that there is a lot of traffic on this email list and you will get many messages. To give you an idea ol just how7 much communication there is on this list, according to the archives, from 28 February 2007 to 8 March 200/ there were 303 individual messages' And this is just over nine days - von do the maths! There is a digest version available in which emails are batched together, so that you get fewer individual messages in your inbox. There are also Statalist archives (see the website) which you should browse beiore posting to the list. It is likely that your question has been asked before! Resources 3 Stata Journal Statu Journal is a peer-reviewed journal about Stata that Is published quarterly. Ir j, available in hard copy and as an electronic version. You can hud our more about Siata journal at www.stata-journal.corn. The journal contains articles written about Stata as well as riser-written software additions. Many of the changes that have occurred throughout the various versions of Stata have been as a result of user input. Some users give feedback to Stata by writing software additions which are programs that do specific tasks that aren't (yet! incorporated into the Stata software. Such uscr-wntten programs are often released with subsequent versions of Stata. These additions are profiled m the Stata Journal for those who are imeresred. It may sound like an enormous bore, but we have brought copies of the journal to the classes we teach to show students that the journal is appealing to advanced users and beginners alike. It really is worthwhile taking a look. Stata help files Without trying to lie ironic, we really want to impress upon you that the Stata help hies are really very helpful. If you want to find out about a specific command, going to the Help menu and querying a command or searching for a keyword (which will lead to the command you need) provides a lot of information. There are explanations of what specific commands do, as well as the options that go along witli each command. Often, there are examples which can help you set up your analysis. Much of the content of help files comes from the Stata user manuals, to which we now turn Stata User's Guide and reference manuals if you purchase Stata irom a licensed vendor, you have the choice of purchasing the reference manuals at the same time. The User's Guide, while a small book, gives you basic introductory information on Stata. A detailed table of contents is found on the Stata website (address above). The reference manuals are a full set of books that, alphabetically, give detailed information about all the commands included in the version you are running (not including user-written additions). The reference manuals are excellent sources of statistical information, as detailed examples often are included, which include annotated discussion of results. There are also subject-specific reference manuals, although these vary by the version ot Stata. In Stata 10, the reference manuals include a separate manual on data management, graphics, programming. 4 Gotting Started with Sfata longitudinal panel data, multivariate statistics, survey data, stir- j, vival analysis, and time-series analysis. The utility of these books cannot be overstated. If you want to become a regular user, you should have access to a set of these manuals! | HOW IS STATA DIFFERENT? New and potential users often ask us how Statu is different. Usually, this actually means 'How is Stata different from SPSS?'. |,. As we were both SPSS users for many years before using Stata, we think we can give some straight answers about the differences. But before we do so, it should be noted that, apart from writing p this book, the authors have no vested interest m Stata as a product We are university teachers who have had to learn as well as teach both programs. We both have a strong interest in research methods, and particularly, we both have an interest in answering research questions in the most effective manner possible. J* We can tell you that, compared to SPSS, the commands in Stata are much more intuitive and less fussy regarding punctuation. If you tear 'syntax' because of your experiences in SPSS, wc S are fairly confident that you will find writing command language much less onerous in Stata. «- Another strength of Stata is that it is user-driven. When there K is a flaw or something that could be improved in the software, Stata listens to its users. In fact, many of the new applications ij incorporated into newer versions were written originally- by users. Related to this point is that Stata, if you are connected to the web and there aren't restrictions on what you can download, is 'web jpj active', This means that you can download new applications that were written by users to perform specific tasks, and use them as commands. These additional user-written programs cover vast -numbers of applications and simply searching for them within Stata and easily downloading and installing these bolt-ons is ^ something that helps Stata stand out. We both originally moved to using Stata because we were working with large complex data sets and found working with them in SPSS to be very cumbersome. If you have experience of working with longitudinal data sets with various different tvpes of file structures, you will see that dealing with these in Stata is much "* quicker and easier. But it isn't the case that SPSS has no strengths over State I hi :p editing of output and the labelling of variables, for cxarnpk. is Getting started 5 much easier in SPSS. SPSS users who are used to having a data window open at the same time as running commands will also find ir Irustrating that this is simply not possible in Stara. Por those who prefer to work entirely with pull-down menus, the newer versions of Stata have comprehensive pull-down menus (although we believe that it is a good thing to move on to saveable command files). Although by no means a complete list of the advantages and disadvantages of Stata and SPSS, it will give you an idea of the reasons why people may or may not change their particular software preference. One of the biggest reasons for not changing is the market dominance of SPSS, although the number of Stata users continues to grow. We personally made the switch when vvc started working with large and complex data sets - but we haven't looked back! GETTING STARTED In this book we assume that you are working with either version 9 or version 10 oi Stata, but the graphics we use to accompany the text are done in version 10. We highlight the major differences between versions 9 and 10 later in this chapter. If you have an earlier version, much of what we discuss in this book will be relevant. As this is an introductory book, we wall be focusing on the beginnings of data analysis, and these basic functions apply to the earlier versions of Stata as well. We also assume you will be using Windows as your operating system, although Stata can be run on Unix, Macintosh, and I.inux. The first thing you should do when you arc getting started with Stata is get acquainted with the various windows that you are presented with when you launch it. Obviously, you need to begin by launching Stata on your computer. Depending on how your computet is set up, this is done by either double-clicking on the Stata icon or selecting Stata from the Programs menu, which you get to by clicking on Start in the left-hand corner of your screen and, then selecting AH Programs, and then looking for Stata m the list of programs. When you first launch Stata, you may find it off-putting. If you are tamiliar with other statistical software programs, particularly SPSS, you could think that Stata looks a lot less user-friendly. What are ail these boxes? Where are my data? And what's with trial black window that looks suspiciously like a DOS screen from Getting Started with Stats way back when? This may instil apprehension if you immediately jj-associate tbis appearance with DOS programming language. But test assured, you don't have to be a master of computing languages to use Staia. What we are going to show you is how these I windows are customizable, and have features that were introduced as a response to user requests. As soon as you get used to the appearance and set up the windows the way you like them, % you will find that Stata is extremely user-friendly indeed. So don't let first impressions put you off. ffL FLAVOURS OF STATA Stata comes in four basic 'flavours' - this is their terminology, not ours! The flavours differ according ro the size of data sets and numbers of variables they can handle. The first flavour ot Stata is Stata/SE, which is especially for large data sets. Stata/SE can handle over 32,000 variables and can fit models including over 10,000 independent variables (we can't imagine a model like this, however). The number of cases or observations it can handle is only limited by the capabilities ot the computer on which it is installed The second flavour of Stata is Stata/MP, which is simply a parallel processor equivalent of Stata/SE. So if you have a computer with multiple processors and run estimations that take a lot of time on Stata/SK, you have the option of switching to Stata/MP, which is essentially the same but much faster. The third flavour of Stata is Intercooled Stata, which is the 'standard'. If you are using Stata at a university lab or have purchased a single license, you probably have Intercooled Stata. This flavour can handle over 2000 variables and include just under 800 independent variables in a single model. Like Stata/SK, the number of observations in the data is only limited by the capabilities ot your machine. The fourth flavour is Small Stata, which is very limited compiled to the othri flavoui . Small Stata can only accommodate yy variables, is limited to iOOO observations, and can only use a nuviinun of »8 independent variables in an estimation. \\ h v lL"\om d i von have? It will say in the top left-hand uiiiiLr of Stun wfuii it l launched. For example it could be """T *-" ' «hu.ii Slows that you have main version 9 'undated n -) ') m Intercooled flavour. Or you may have vh'ch 'fin"' you have main version 10 (10.1) also m Tntercooleu flavour. Organizing windows in Stata 7 ORGANIZING WINDOWS IN STATA Mara launches with four windows: Review, Variables, Results and Command. There are considerable differences between versions 9 and 10, Prior to version 9, the window functions were fairly simple and mostly required yon to manually change the size and position, in version 9 the windows got substantially more complicated in the default setting with pinning, docking and floating. In version 10 the default window settings returned to simple stretch and drag but with pinning, docking and floating as options. As there are quite a tew differences between versions 9 and 10 at start-up, we tackle each in turn. Version 9 if the four windows (Review, Variables, Results and Command) .ne not all present, or just for die sake of starting on the same page as us, select from the menus at the top of the screen: Prefs ~> Manage preferences -> Load preferences -4 Factory settings if you follow the above steps, you will get windows that look much like those below. Of course, your 'flavour' might be different (as indicated in the top left-corner), but even if it is, it will look the same upon launching. And obviously, your licensing and serial numbers will be different. Getting Started with Stata When starting out with version 9 we strongly recommend you disable the pinning, docking and floating functions so that you can avoid problems with windows disappearing or turning into tabs when you didn't intend them to. You can always come back to this later when you want to learn more about changing the display options available to you (see Box 1.1 for more information on this). Select Prefs -> General Preferences Then click on the Windowing tab and uncheck Use docking guides and Enable ability to dock, undock, pin, or tab windows and then click Apply, You will have to restart Stata for the effects to take place. L lur rijtiL±t c '9 It hit ft • _ 1 h- il> I iriwsuüllhack hurlei ;iie (byte)1' F lir.- I idogi ri-.au iriciilaJeiJ* t ^ Hi id r n1 ii I pin . f b 'tri |1 tf undu )m5 i ^ rjK HI Is M I ird"" rli M rUudruT^ uli I "j Make Re**, wtidc-vj (bat It is possible to resize the windows to suit your own preferences by dragging and stretching them. If you resize your windows, you can select Prefs —> Manage preferences —> Save preferences ■■-► new preferences set Then a dialogue box will appear which allows you to 'name' your window settings. This is particularly useful if you share your Organizing windows in Stata 0 computer with another Stata user or if you have different preferences for your windowing for different projects you are working on. If you relaunch Stata and the window preferences have changed, provided you have saved your preferences, you just go to Prefs -» Manage preferences -» Load preferences —> rf;.x»s Piracng, dccKing, and liaat.ng windows ar^. a detault feature -n vetsfon 9. Pinning It yen nave wjicn 8 M"i "oak in the top >'\qht natc eotnBi o: tho Re«iPW Vaaablee, and Conuaand wndows, you *il sec < i>v ~ synno1 rloaes 'he vundow (is in many piogtaiis', hut th» ■ a,tr,bel s usea for pinniiq' (loticn, it is »baperi like a piei It yoM click on the - k \n the Review window you wttl see that the Review window vaei^iibs and becomea * tab on the iefPK nd side |f\" (It- Vanai.ie1 window it toe «11 nocer o a tat; F1.- I-* F *r: Da-=, Q.pU. H-et ."rdc > tVp f you olick on trie won tor l-teYiov and Vuc.Ut.ica, you wil> uee that trwy reappear, but ouiekiy >amsh oricp you click n any othei Sta ,. wndrw, if ywt loot eai?*a% on 1h' Rf view and Vanablss wndowa wlien thny 'reappear', you will notice that the " symbol his, change^ io . thi- ^idc»i,= pot, ion mfafi. hat the wndov> i's aoI 'p>rnec\ as .->|-|"S v/isoon in Sp,e above screen capture), holding ttawn the ie**-click button on your rnpuse, and pulling the box somewhere elsft on the scroan -nutate- e* "Tout- appear A compass-tike sei of arrows ha? arapeart-.rt in the middle of the screen and additional arrows appear in at th« top, bottom and nrjhl nad left sides ot >r& Stats screen What do f hesa do? tf we .se'ect either of the right arrows' (either the centre one or the one on rro tor fy^t), wic-'ow repositions at* below on thy far right-hand side: <^r- ,' ■ -« Jg-J^s-^- 12 Getting Started with Stata You could crag it to different positions, docking it on top, below, or beside »ne f'e ew window ~'re b&-t way to famt»ar,zs jju.se!* with these functions :t to piay around with trient Floating ... . Windows can 'float' - in other words, on'y appear on screen when you click on them, and at other times appear as tabs in your Windows task bar. if you double-click on the blue parts of She individual Variables, Review, and Command windows, tbay will float. They will appear in your task bar and only become visible when you click on them. We have had many students do this by mistake and get very frustrated when they can't get their windows 'back'! All you need to do fo restore them fo non-floating is vdiok on thtr.it 3o UtaL they ieappear in ihe Sia&a window, and then double-click anywhere on the blue bar of the window to lock them into 'non-fioating'. in version 10 you need to enable these features by ticking the hoses in the Windowing tab in the puli-down menu. Edit -v Preferences -s- General Preferences '1 Peuill Cdots Viewer Cobts . Dale L.Jiloi VMwg ; Inlem^ i •J I Imr nil "indw .uulllja'-1 bull- |b' f-= \ i I LY-able -sbilitu lo pin or unpri wrAv--., j "kncbleitiMuiti cock jrijg.;-,. oi idb v.md'> M--i p"'itiiHoi«- fn.-rfc-cMingRi--^:! 'tWirHt ul:wnJu',''ll.iai 3, i Can.v Organizing windows in Stata 13 Version 10 Version 10 launches with a windows layout that is the same as when it was last closed. This is fine if you are the only user but if you share a computer with another Stata user, or want to save different layouts for different tasks, then you can save these preferences. To get to the layout you like simply stretch and drag the windows then save your preference using this pull-down menu: To save your own preferences select: Edit -t Preferences —> Manage preferences — Save preferences — New preferences set Then a dialogue box will pop up winch allows you to 'name' your window settings. Then if you launch Stata and the window preferences have changed you just go to Edit -r Preferences ■-> Manage preferences -> Load preferences --> -name of your preferences > if you would like to start again with the factory settings follow: Edit Preferences —> Manage preferences ■ — Load preferences --> Factory settings 14 Getting Started with Stata Our preferred layout is shown below: WHERE DID MY WINDOW GO? Sometimes, by accident, you may close one of the windows on your Stata screen. It, lor example, your Variables window 'vanishes', it is quite easy to get it back - just, go to the menu at the top of the screen and click Window -> Variables WINDOWS IN STATA AND WHAT THEY DO The four windows of Stata that you see upon start-up all have-very different purposes. The Command window The Command window opens when >tata is launched and is a quick way of running commands, but only if you are familiar with the basic commands. By default, tins window is located at the bottom of the Stata screen. We will talk more about typing commands into this window in the next section on 'working interactively with Stata', §1 IP is Windows in Stata and what they do 1ha Rev'pw win j -)w Ih Vr\it \ urn is. by default, positioned in the upper left-' nJ < i- it St r t Ail oi youi. commands are recorded here. If (Hi i'i ruiim" ito the Command window, they will appear >n he r> »i > > 111 •. The Review window is particularly handy ben e e li 1 ng your data because if you, ior example, do ill iiito fi ' 1 rion ol a variable, the command will appear in di -» nninmgi to save on typing. If you double-click 11 v ,,n s til, is \ Kevicw window, Stata will execute them, in version fu vou can select multiple lines in the Review >ind'>w Ly 'i .Mm' down the Shift key and then double-clicking 1 jp» til' k dl t > 1111, Also m version 10 you can list the com-1111 1 in ulIx i 1 1 • riding or descending order by clicking on the ComTldiw he i in/ [ he order changes and this is indicated by the anow next 10 the Command heading and the numbers next to m ..omnium f uuplr Jbisn. - 'il 11 Ui nil- .-r.tI ^H|[ii|'\, u -inq 1 I1!- uainidriu 1 'jhqscaie d..jho - 1 " ir, 1 i-nts and f.ett/nqsi, Iso in version 10, the Review window indicates which com-lamii retimed an error by displaying tiiem in red with the error xie on the right. It is possible to sort according to the error codes ny clicking on the _rc heading. In this way you can easily delete the commands that caused an error if you want to convert your 16 Getting Started with Stata Review window to a do file, To save the commands in the Review window as a do file simply right-click when one oi the commands is selected and you will see an option to Save Review Contents which will automatically save them in a do file format. ! eommsno r i- i tbrig-ipeval'n'i.r. esl, i- C j rt i d ttingsipevaiin\Dc!sk. mnprn j The Variables window ; When you have a data set loaded, the variable names and labels appear in this window. Sometimes you need to stretch out the window widthwise to see the variable labels - if the variables číre ^ labelled in your particular data set. In version 10 you will see that the type and format of each variable is also listed in the window. >— m The Results window In this window, the results of the commands are presented. You should note that Stata does not 'save" the results here indefinitely and that by default, only 32,000 bytes of memory are allocated to the 'buffer'. To permanently save your results you will need to use jPf a log file that we introduce later in this chapter and tackle in more detail in Chapter 2. You can change the bufier to up to 500,000 ^ bytes either by typing in the Command window; — set scrollbufsize 100000 fa or by using the pull-down menu: pift Prefs —.> General Preferences (version 9) Edit -» Preferences -» General Preferences (version 10) g-- Then click on the Windowing tab and at tlie top you will see the up and down arrows to change the size of the bufier. Whatever |p sue you allocate (between 10,000 and 500,000 bytes) will be Interacting with Stata 17 remembered by Stata and then become the default every time Stata is launched. INTERACTING WITH STATA There are three ways to 'interact' with Stata to tell the program what you would like to do with the data. Here we have callea these ways using pull-down menus, 'working interactively', and writing do files. Before we get on to these different ways ol interacting with Stata, it is important that we clarify our terminology. I here is a good deal of confusing terminology surrounding the ways to interact - some comes from the language used by Stata, but other users carry over language from other software packages, This can be a little confusing for the beginner. For example, in SPSS the written text hies for commands arc called 'syntax flies' but often referred to as 'code'. The Stata name for a text file of commands is a do file, which has a .do extension (see Box 1.2 for other file extensions). That distinguishes it from the SPSS syntax files, but how do yon refer to the actual text in the file? Some users carryover the word syntax but we prefer to use commands. So, m a do file we have a series of commands and these commands have options. ! Through pulldown menus If vou have used the Windows versions of SPSS then using pulldown menus to manipulate and analyse data will be familiar to ; you. Version 8 of Stata was the first version to incorporate pulldown menus and, while we strongly recommend the use of do ■ files, the pull-down menus are useful when getting to know Stata, especially lor graphing. You will see in the pull-down menus under Statistics, for example, a series of options for various types < of statistical tests. It should be pointed out early on to the new user that there are more statistical possibilities in Stata than there , are options in the pull-down menus which open dialogue boxes. f It is not possible to access some types of statistical analyses in the pull-down menus - they must be entered as commands in either a i do file or the Command window. Through the Command window | A second way of using Stata is through writing commands in the Command window and hitting the Enter key. The command then » 18 Getting Started with Stata appears in the Review window, and as discussed earl' > n I >-saved as a do file. The Command wandow can be used to directly call an ti Ji i-logue boxes in the same way as, the pull-down menu- u - i" »'> For example, typing tSb svenmarise in the Comiiiai <* « n |V, then hitting the Enter key will bring up the dialogue I) > i ei l> the pull-down menu to produce summary statistics (see ( h ; cei and Box 5.4). in the Command window the tsped commands c£ one line without any problem. However, in a do file if t miuiiJ runs over one line (or you want co break up the cornnian 11. n of editing) then there needs to be a /// at the end of each h i< i wff t the last. This /// ceils Stata to ignore the line break anu , o itu ue reading the command as if on a single line. We use this ///' notation in this manual when our ccnn.uia.nds run over a single hnc. If you are using the Command wsndovv to follow or adapt these com mands, then you can ignore the continuation notation ///, Thmirah the construction of do files I i l | i 1 i ild i | 11 i lit l) J It i i t i t hit them again) later. For those familiar with the syntax window in SPSS, the do file editor in Stata is much the same. h 1 i li c r rl c t rl e s window - 9 - in version 9 and D - in version 10 - a do file c I I j e i 11 ill i| 1 in lar to Notepad) in which you can type, copy, cut and paste text. I r i r In \ suggest you start by only having one open, but note this function ! I i li I (t I II t ii 1 i I 1 epi i '1 I l t f 1 i hi )i I i | c your data. We will focus more on the use of do files later. We recommend using do Ides as soon as possible but to start out using ll t i 1 1 ii t t h raand wnndovv. 11 i d ii hi t i 11 c i 11 l i i i i d lr open. The open do files are listed as tabs below the toolbar; hi this ^ n s i i ill i b h ! i n dee i i i 1 U i I t it 1 I u >r v i 1 i i ill 1 i 1 i I f* l s in b il I lid ll e 5* interacting with Stata 19 other two are dimmed, fo bring one of the others to the front simply click on the name. Si it 1 stinguishes between being asked to do a command and nir 14 jd to run a command. Both execute the commands but ■ 1 ml in what command has been used and produces any t does them while run is silent or not showing the < th i ; can be a little frustrating when getting to know Stata. ■*" rrri n th we suggest that you use do all .he title The do icon i h tl est right on the do file editor tool i.ii . The one to its I it i rht r jn icon. If you look closely you can "c rhit the do icon f i hm o" it which indicate output wheieas the run icon is blank h \ i '<- ih u it runs silently. Under the Tools pull-down menu are some other options for co rud rur It is important to understand that it you just dick the do , >n i ti tlic toolbar (or choose Do from the pull-down menu) 1 i >t it i will do the whole do file starting from the top. If you , it to Co a hue or two then you can select those lines m the i< bit tS ii either click the do icon on the toolbar (or choose Do tu.m th r ili-dov n imrnui and siati will only execute those com-m in 1 I he 1 isi ' »t ti in '. r-t p< .siti " d. ..ursor in the do file and Ih i m IV» to B: UOilr huh Tv null down menu. In this case tn. nl h> ill i oiiteiai'ds ti ni whcie tlic cursor is to the end of the do hie. t _ I. H i ii ^1 l.i ,1 ,1- n hl,.hi|l+t 1 It should be noted here that there are other text editors that people use to save their commands, hut for the purposes of this book, we will use the editor provided in Stata. 20 Getting Started with State LOG FILES Because you can't save the contents of the results screen in Stata (like the output window in SPSS, if yo ' - ;d that program before;, you should quickly get into tl f using log files. I ike the name suggests, log files make ; f your Stata ses- sion and include all your commands and e nl m one document. You will find an icon - '.;c in version 9 i tl _ i version 10 - on tlie toolbar which is the button for beg,i,nue „ log file. We will return to log files in the next chapter, but for now, just remember that these are the types ot files we use in Stata to make a record of our session. Box 1.2: Pile extensions There are four file extensions in Stata that you should get to know: « data li;,".t b„,r, '!tvF.sion ,dph WHERE ARE MY DATA? If you are accustomed to other statistical software, you might be puzzled as to how to view your data. In SPSS, for example, there is a Data Viewer window that is open even while you are using the pull-down menus to select your commands. In Stata, the data is 'behind the scenes', like the log file. If you look on your menu liar, you will see these two icons: yj in version 9 and 0'.. in version 10. The one on the left is the Data Editor and the one on the right is the Data Browser (with the magnifying glass). You can physically change the data in your data file in the Data Editor, but not m the Data Browser. Only the Data Editor or the Data Browser may be open at one time (not both). Also, you must close the Data Editor and Data Browser before Stata will run any commands. Setting directories Kow that we have an idea of what all the windows are for, it is time to turn to how to really 'get started'. We begin by preparing Stata to work with data and setting up our directories. ALLOCATING MEMORY TO STATA When Stata launches, there is a note in the Results window that tells you how much space has been allocated to data. This varies by the flavour of Stata, network and the default settings on your computer/ network. On the particular computer that we use, Stata opens with 1 Mb allocated to memory. This may seem like plenty, but a lot of data sets are much bigger than this and therefore it is necessary to increase the allocation of memory. To use your available memory efficiently we suggest that you set the memory to only slightly larger than the data set to be used. If, for example, we want to change the allocated memory to 50 Mb, we just use the command: set mem 50m You can type whatever amount of memory you require here depending on the size of the data set you are using and the specifications of your computer. If you move on to analysing large survey-type data then you may need to specify 250-500 Mb of memory. If you decide, after some practice, that you typically use 50 Mb (or some other amount) of memory every time you use Stata, you can type set mmm 50m, permanently This memory allocation will take effect by default every time you start Stata. SETTING DIRECTORIES You can, and should, make sure that all of your files for a particular project are saved to the same directory on your computer. This will make it easier to retrieve any file related to a particular project and save you retyping long file locations every time you want to open or save data. You can tell Stata to create a directory using the command mkdir (make directory) - a new directory is created where you 22 Getting Started with State can store all of our data, syntax, and log files. So if you type in the command window: inkdii /projeotnaste Stata will make a folder in your (S drive called projeetname. Of course, you would want to change this to where you want your data and do files stored. It might not be on the C drive and you probably would want a more meaningful name for your folder! Alternatively, you can create the folder you want to use first through your software and its tile and folder management functions. You can then use the command cd to tell Stata to change directory so that your files arc stored there. Type: eel c:/projeetname In version 10 you can change the working directory using the pull-clown menu: File -» Change working directory Then browse to the location of the directory/folder you wish to use. Now if you save any files without explicitly defining another directory, your flies will be saved in this directory. So if you have a data set open and you want to save it, you can simply just type save nameof data and this file would now appear in your new directory.