The post Data Analysis Using STATA: Use and Interpretation appeared first on HKT Consultant.
]]>Most of its users work in research, especially in the fields of economics, sociology, political science, biomedicine, and epidemiology. According to StataCorp (2016), Stata is “a complete, integrated statistical software package that provides everything you need for data analysis, data management, and graphics”. Basically, Stata is a software that allows you to store and manage data (large and small data sets), undertake statistical analysis on your data, and create some really nice graphs.
Stata allows you to write code or use menus to perform your analysis. Stata has two primary menu tabs: Graphics and Statistics. Within “Statistics” there are twenty-one sub tabs and numerous tabs within those tabs. Within “Graphics” there are twenty-one tabs as well (you think the people at Stata like to play Black Jack?). I admit, this can be a bit daunting and time consuming if you are trying to find a specific function. But wait, there’s more. In the command box you can type “help” and what you are looking for. The key point here is I don’t waste time trying to find what I’m looking for. After running the command through the menus method the code shows up in the “Review” box. I can then copy and paste the command into a “do-file”. A “do-file” is the text document that allows you to submit more than one command to Stata at once.
Stata allows you to have more than one do-file opened at a time. This is a big plus because it makes it easy to copy and paste from other project do-files into the current do-file. Using do-files is significantly quicker than using the menus if you have created template do-files, especially for creating graphs. There are so many options for creating a graph. It takes less than a minute to copy from a template and paste the commands into your current project. Stata is extremely efficient running repetitive analysis when incorporating macros and loops in a do-file. This sounds like it may be difficult but it’s not.
How well is Stata supported by Stata Corp? On average Stata sends out updated files every two months with new features and/or any fixes to reported glitches. The reference guide for Stata 13 is 281 pages filled with examples and links to the data sets used in the examples. The professional community also provides incredible support. Stata allows third party written commands (also known as modules) to be imported into the software. The website http://ideas.repec.org/s/boc/bocode.html is a warehouse for hundreds of third party written commands which have been tested before made public. Running a search for “logistic” returned 128 results. The bottom line is Stata will run every analysis that the other major statistical packages can, if not more. It is a very efficiently organized program to learn to use. Third party professionals are continuously offering new functions. Stata adds new features without charging a “new” version fee. All this and the added bonus are reasonably priced and has no add-on charges.
There are four major builds of each version of Stata:
Small Stata, which was the smaller, student version for educational purchase only, is no longer available. This software is commonly used among health researchers, particularly those working with very large data sets, because it is a powerful software that allows you to do almost anything you like with your data.
It’s important to note that Stata is not the only statistical software – there are many others that you may come across if you pursue a career that requires you to work with data. Some of the other common statistical packages include SPSS and SAS (yes, they all start with ‘s’!). The focus for this session, however, is on Stata.
The post Data Analysis Using STATA: Use and Interpretation appeared first on HKT Consultant.
]]>The post How to Install and Activate Stata on a Windows Computer appeared first on HKT Consultant.
]]>1. Go to http://download.stata.com/download or download directly Stata here or here. The following login box should appear in your browser. Enter in your username and password (as provided in the email from Survey Design and Analysis), as well as the other information requested, then click ‘Log in’:

2. Select the ‘Windows’ option for your operating system:

3. Then click on ‘Download SetupStata_xx.exe’:

4. The Setup file should now be downloading, and the following should appear in the bottom left corner of your browser:

NOTE: Please make sure that you have a good internet connection to be able to download the package.
1. Once the file is downloaded, click on the SetupStata17.exe file. You will see the following dialogue box appear, please wait until the process is finished:









1. Type stata in the search bar and then click and open Stata


3. Ensure the following box is checked to register for access to Technical Support. Then click ‘Finish’. The licence is now activated.

The post How to Install and Activate Stata on a Windows Computer appeared first on HKT Consultant.
]]>The post How to Install and Activate Stata on a Mac Computer appeared first on HKT Consultant.
]]>1. Go to http://download.stata.com/download. The following login box should appear in your browser. Enter your username and password (as provided in the email from Survey Design and Analysis), as well as the other information requested, and click ‘Log in’:




1. Once the file is downloaded you can run the Stata17.dmg file from your browser by clicking on the download arrow in the top right corner of the browser and then double-clicking the file. Alternatively, you can navigate to your Downloads folder and the Stata17.dmg file should be located here (as shown below):






7. Confirm where you would like Stata to install. The default is the Macintosh HD, however if you wish to change this to another location click on ‘Change Install Location …’, and once you are happy with the install location click ‘Install’:




1. To find Stata, go to your Applications folder and find a folder called Stata. Your new Stata program is located in this folder. Double-click it to run. Otherwise, the Stata program should have been added to your Launchpad screen, so if you use this to start programs you should be able to find it there too. Run the Stata program.
2. You will then be asked to initialise your licence, enter details in the following dialogue box (please copy-paste your Serial number, Code and Authorization to avoid typing errors):

3. Ensure the following box is checked to register for access to Technical Support. Then click ‘Finish’. The licence is now activated.

The post How to Install and Activate Stata on a Mac Computer appeared first on HKT Consultant.
]]>The post Quick Overview of Stata User Interface appeared first on HKT Consultant.
]]>The five main windows are the History, Results, Command, Variables, and Properties windows. Except for the Results window, each window has its name in its title bar. These five windows are typically in use the whole time Stata is open. There are other, more specialized windows such as the Viewer, Data Editor, Variables Manager, Do-file Editor, Graph, and Graph Editor windows – these are discussed later in this manual.

Commands are submitted to Stata from the Command window. The Command window supports basic text editing, copying and pasting, a command history, function-key mapping, filename completion, and variable-name completion.
From the Command window, pressing:
Page Up steps backward through the command history.
Page Down steps forward through the command history.
Tab autocompletes a partially typed variable name when possible or presents a list of similar names if there could be more than one completion. Further typing will narrow the list. As soon as the name is complete, the full name will be inserted. If the name starts with a double quote, Tab attempts to autocomplete a filename in the same manner.
The command history allows you to recall a previously submitted command, edit it if you wish, and then resubmit it. Commands submitted by Stata’s dialogs are also included in the command history, so you can recall and submit a command without having to open the dialog again.
The Results window contains all the commands and their textual results you have entered during the Stata session.
You can scroll through the Results window to look at work you have done, it is much simpler to search within the Results window by using the find bar. By default, the find bar is hidden. You can expose it by selecting Edit > Find ….
You can clear out the Results window at any time by right-clicking in the Results window and selecting Clear results from the contextual menu. This action is not undoable.
The Variables window shows the list of variables in the dataset, along with the properties of the variables. By default, it shows all the variables and their variable labels. You can change what properties get displayed by right-clicking on the header of any column of the Variables window.
Click once on a variable in the Variables window to select it. Multiple variables can be selected in the usual fashion, either by Ctrl-clicking on nonadjacent variables or by clicking on a variable and Shift-clicking on a second variable to select all intervening variables.
Double-clicking on a variable in the Variables window puts the selected variable at the insertion point in the Command window.
The leftmost column of the Variables window is called the one-click paste column. You can also send variables to the Command window by hovering the mouse over the one-click paste column of the Variables window and clicking on the arrow that appears. The one-click paste column can be shown or hidden in the same fashion as the other columns in the Variables window.
The Variables window supports filtering and changing the display order of the variables. Text entered in the Filter variables here field will filter the variables appearing in the Variables window. The filter is applied to all visible columns and shows all variables that match the criteria in at least one column. By default, the filter will ignore case and show any variables for which at least one column contains any of the words in the filter. Clicking on the wrench on the left will allow you to change this behavior as well as add or remove additional columns containing information about the variables.
You can change the display order of the variables in the Variables window by clicking on any column header. The first click sorts in ascending order, the second click sorts in descending order, and the third click puts the variables back in dataset order. Thus, clicking on the Name column header will make the Variables window display the variables in alphabetical order. Sorting in the Variables window is live, so if you change a property of a variable when the Variables window is sorted by that property, it will automatically move the variable to its proper location. Reordering the display order of the variables in the Variables window does not affect the order of the variables in the dataset itself.
Right-clicking on a variable in the Variables window displays a menu from which you can select
Items from the contextual menu issue standard Stata commands, so working by right-clicking is just like working directly in the Command window.
If you would like to hide the Variables window, click on its close button.
To reveal a hidden Variables window, select Window > Variables.
The Properties window displays variable and dataset properties. If a single variable is selected in the Variables window, its properties are displayed. If there are multiple variables selected in the Variables window, the Properties window will display properties that are common across all selected variables.
Clicking the lock icon in the Properties window title bar toggles the ability to alter properties of the selected variables. By default, changes are not allowed. Once the properties are unlocked, you can make any changes to variable or dataset properties you like. Each change you make will create a command that appears in the Results and Command windows, as well as in any command log, so the changes are reproducible. Using the Properties window is one of the simplest ways of managing notes, changing variable and value labels, and changing display formats.
Clicking the arrow buttons next to the lock icon will select the previous or next variable shown in the Variables window, and that selection will be reflected in the Properties window. If you would like to hide the Properties window, click on its close box. If you would like to reveal a hidden Properties window, select Window > Properties.
You should also investigate the Variables Manager, because it extends these capabilities and provides a good interface for managing variables.
The History window shows the history of commands that have been entered, with unsuccessful commands and their error codes in red, by default.
The toolbar has two tools for manipulating the contents of the History window. Clicking on the Filter button in the History window title bar toggles the visibility of these tools. Text entered in the Filter commands here field will filter the commands appearing in the History window. By default, the filter ignores case and finds any commands containing any of the words in the filter. Clicking on the wrench on the left allows you to change this behavior. You can hide the commands that produced an error by clicking on the Filter errors button .
To enter a command from the History window, you can:
Right-clicking on the History window displays a menu from which you can select various actions:
This is the toolbar:
![]()
The toolbar contains buttons that provide quick access to Stata’s more commonly used features. If you forget what a button does, hold the mouse pointer over the button for a moment, and a tooltip will appear with a description of that button.
Buttons that include both an icon and an arrow display a menu if you click on the arrow. Here is an overview of the toolbar buttons and their functions:
Open opens a Stata dataset. Click on the button to open a dataset with the Open dialog.
Save saves the Stata dataset currently in memory to disk.
Print displays a list of windows. Select a window name to print its contents.
Log begins a new log or closes, suspends, or resumes the current log.
Viewer opens the Viewer or brings a Viewer to the front of all other windows. Click on the button to open a new Viewer. Click on the arrow to select a Viewer to bring to the front.
Graph brings a Graph window to the front of all other windows. Click on the button to bring the Graph window to the front. Click on the arrow to select a Graph window to bring to the front.
Do-file Editor opens the Do-file Editor or brings a Do-file Editor to the front of all other windows. Click on the button to open a new Do-file Editor. Click on the arrow to select a Do-file Editor to bring to the front.
Data Editor (Edit) opens the Data Editor or brings the Data Editor to the front of the other Stata windows.
Data Editor (Browse) opens the Data Editor in browse mode.
Variables Manager opens the Variables Manager.
Show more results tells Stata to continue when it has paused in the middle of long output. Click on the arrow to choose whether to run the command to completion.
Break stops the current task in Stata.
There are two ways by which you can tell Stata what you would like it to do: you can use menus and dialogs, or you can use the Command window. We will discuss the menus and dialogs here.
Stata’s Data, Graphics, and Statistics menus provide point-and-click access to almost every command in Stata. As you will learn, Stata is fully programmable, and Stata users can even create their own dialogs and menus. The User menu provides a place for programmers to add their own menu items. Initially, it contains only some empty submenus. As an example, suppose you wish to perform a Poisson regression. You could type Stata’s poisson command, or you could select Statistics > Count outcomes > Poisson regression, which would display this dialog:


This dialog provides access to all the functionality of Stata’s poisson command. Because the dependent and independent variables must be numeric, you will find that the combo box will display only numeric variables for choosing. The poisson command has many options that can be accessed by clicking on the multiple tabs across the top of the dialog. The first time you use the dialog for a command, it is a good idea to look at the contents of each tab so that you will know all the dialog’s capabilities.
The dialogs for many commands have the by/if/in and Weights tabs. These provide access to Stata’s commands and qualifiers for controlling the estimation sample and dealing with weighted data.
The dialogs for most estimation commands have the Maximization tab for setting the maximization options. For example, you can specify the maximum number of iterations for the optimizer.
Most dialogs in Stata provide the same six buttons you see at the bottom of the poisson dialog above.
OK issues a Stata command based on how you have filled out the fields in the dialog and then closes the dialog.
Cancel closes the dialog without doing anything—just as clicking on the dialog’s close button does.
Submit issues a command just like OK but leaves the dialog on the screen so that you can make changes and issue another command. This feature is handy when, for example, you are learning a new command or putting together a complicated graph.
Help provides access to Stata’s help system. Clicking on this button will typically take you to the help file for the Stata command associated with the dialog. Clicking on it here would take you to the poisson help file. The help file will have tabs above groups of options to show which dialog tab contains which options.
Reset resets the dialog to its default state. Each time you open a dialog, it will remember how you last filled it out. If you wish to reset its fields to their default values at any time, simply click on this button.
Copy command to Clipboard behaves much like the Submit button, but rather than issuing a command, it copies the command to the Clipboard. The command can then be pasted elsewhere (such as in the Do-file Editor).
The command issued by a dialog is submitted just as if you had typed it by hand. You can see the command in the Results window and in the History window after it executes. Looking carefully at the full command will help you learn Stata’s command syntax.
In addition to being able to access the dialogs for Stata commands through Stata’s menus, you can also invoke them by using two other methods. You may know the name of a Stata command for which you want to see a dialog, but you might not remember how to navigate to that command in the menu system. Simply type db commandname to launch the dialog for commandname:
. db poisson
You will also find access to the dialog for a command in that command’s help file.
As you read this manual, we will present examples of Stata commands. You may type those examples as presented, but you should also experiment with submitting those commands by using their dialogs. Use the db command described above to quickly launch the dialog for any command that you see in this manual.
The post Quick Overview of Stata User Interface appeared first on HKT Consultant.
]]>The post Using the Stata Viewer appeared first on HKT Consultant.
]]>The Viewer is a versatile tool in Stata. It will be the first place you can turn for help within Stata, but it is far more than just a help system. You can also use the Viewer to add, delete, and manage third-party extensions to Stata that are known as community-contributed features; to view and print Stata logs from both your current and your previous Stata sessions; to view and print any other Stata-formatted (SMCL) or plain-text file; and even to launch your web browser to follow hyperlinks.
This chapter focuses on the general use of the Viewer, its buttons, and a brief summary of the commands that the Viewer understands. There is more information about using the Viewer to find help in [GSW] 4 Getting help and for installing community-contributed features in [GSW] 19 Updating and extending Stata—Internet functionality.
To open a new Viewer window (or open a new tab in an existing Viewer), you can either click on the Viewer button,
, or select Window > Viewer > New Viewer.
Viewer buttons
The toolbar of the Viewer has multiple buttons, a command box, and a search box.

The Find bar is used to find text within the current Viewer. To reveal the Find bar at the bottom of the window, click on the Find text in page button:
![]()
The Find bar has its own buttons, fields, and checkboxes.

Viewer’s function
The Viewer is similar to a web browser. It has links (shown in blue text by default) that you can click on to see related help topics and to install and manage third-party software. When you move the mouse pointer over a link, the status bar at the bottom of the Viewer shows the action associated with that link. If the action of a link is help logistic, clicking on that link will show the help file for the logistic command in the Viewer. Middle-clicking on a link in a Viewer window (Ctrl+clicking if you do not have a three-button mouse) will open the link in a new tab in the Viewer window. Shift+clicking will open the link in a new Viewer window.
You can open a new Viewer by selecting Window > Viewer > New Viewer or by clicking on the Viewer button on the toolbar of the main window. Entering a help command from the Command window will also open a new Viewer.
To bring a Viewer to the front of all other Viewers, select Window > Viewer and choose a Viewer from the list there. Selecting Close all Viewers closes all open Viewer window and tabs.
Viewing local text files, including SMCL files
In addition to viewing built-in Stata help files, you can use the Viewer to view Stata Markup and Control Language (SMCL) files such as those typically produced when logging your work (see [GSW] 16 Saving and printing results by using logs) as well as plain-text files. To open a file and view its contents, simply select File > Open…, and you will be presented with a dialog:

You may either type in the name of the file that you wish to view and click on OK, or you may click on the Browse… button to open a standard file dialog that allows you to navigate to the file.
If you currently have a log file open, you may view the log file in the Viewer. This method has one advantage over scrolling back in the Results window: what you view stays fixed even as output is added to the Results window. If you wish to view a current log file, select File > Log > View…, and the usual dialog will appear but with the path and filename of the current log already in the field. Simply click on OK, and the log will appear in the Viewer. See [GSW] 16 Saving and printing results by using logs for more details.
Viewing remote files over the Internet
If you want to look at a remote file over the Internet, the process is similar to viewing a local file, only instead of using the Browse… button, you type the URL of the file that you want to see, such as https://www.stata.com/man/readme.smcl. You should use the Viewer only to view text or SMCL files. If you enter the URL of, say, an arbitrary webpage, you will see the HTML source of the page instead of the usual browser rendering.
Navigating within the Viewer
In addition to using the scrollbar to navigate the Viewer window, you also can use the up and down arrow keys and Page Up and Page Down keys to do the same. Pressing the up or down arrow key scrolls the window a line at a time. Pressing the Page Up or Page Down key scrolls the window a screen at a time.
Printing
To print the contents of the Viewer, right-click on the window and select Print…. You may also select File > Print > Viewer name or click on the Print toolbar button,
, to print.
Tabs in the Viewer
A Viewer window can have multiple tabs. You may view different files or different views of the same file in different tabs. Clicking on the Open new tab button, +, will open a new tab in the current Viewer window. You can change the order of the tabs within a Viewer by dragging the tabs along the tab bar within the window. If you drag a tab and drop it within the body of the same Viewer window, a menu will appear. If you select New Horizontal Tab Group, the Viewer window will be split horizontally. This is useful for having two views of the same file at different places in the file. Similarly, if you select New Vertical Tab Group, the Viewer window will be split vertically. This is useful for comparing two similar files side by side.
Once you have created a horizontal or vertical tab group, if you drop a tab inside a group, you will get the choice of creating a similar new group or moving the tab to the selected group.
Right-clicking on the Viewer window
Right-clicking on the Viewer window displays a contextual menu that offers these options:
In other contexts, there could be more items displayed in the contextual menu.
Searching for help in the Viewer
The search box in the Viewer can be used to search documentation. Click on the magnifying glass; choose Search all, Search documentation and FAQs, or Search net resources; and then type a word or phrase in the search box and press Enter. For more extensive information about using the Viewer for help, see [GSW] 4 Getting help.
Commands in the Viewer
Everything that can be done in the Viewer by clicking on links and buttons can also be done by typing commands in the command box at the top of the window or on the Stata command line. Some tasks that can be performed in the Viewer are
Type contents to view the contents of Stata’s help system.
Type commandname to view the help file for a Stata command.
Type keyword to search documentation, FAQs, and net resources for a topic.
Type search keyword to search documentation, FAQs, and net resources for a topic. Type search keyword, local to search only documentation and FAQs for a topic.
Type search keyword, net to search only net resources for a topic.
Type net from https://www.stata.com/ to find and install Stata Journal, Stata Technical Bulletin, and community-contributed commands from the Internet.
Type ado to review community-contributed packages you have installed.
Type ado uninstall to uninstall community-contributed packages you have installed on your computer.
Type view filename.smcl to view SMCL files.
Type view filename .txt to view text files.
Type view filename .log to view text log files.
Type type filename.smcl in the Command window to view SMCL files in the window.
Type type filename .txt in the Command window to view text files in the window.
Type type filename .log in the Command window to view text log files in the window.
Type browse URL to launch your browser.
Using the Viewer from the Command window
Typing help commandname in the Command window will bring up a new Viewer showing the requested help.
Source: STATA (2021), Getting Started with Stata for Windows, Stata Press Publication.
The post Using the Stata Viewer appeared first on HKT Consultant.
]]>The post Getting help in Stata appeared first on HKT Consultant.
]]>Stata’s help system provides a wealth of information to help you learn and use Stata. To find out which Stata command will perform the statistical or data management task you would like to do, you should generally follow these steps:
Let’s illustrate the help system with an example. You will get the most benefit from the example if you work along at your computer.
Suppose that we have been given a dataset about antique cars and that we need to know what it contains. Though we still have a vague notion of having seen something like this while working through the example session in [GSW] 1 Introducing Stata—sample session, we do not remember the proper command.
Start by typing sysuse auto, clear in the Command window to bring the dataset into memory.
Follow the above approach:

Stata will now search for “dataset contents” among the Stata commands, the reference manuals, the Stata Journal, the FAQs on Stata’s website, and community-contributed features. Here is the result:

Upon seeing the results of the search, we see two commands that look promising: codebook and describe. Because we are interested in the contents of the dataset, we decide to check out the codebook The [D] means that we could look up the codebook command in the Data Management Reference Manual. The codebook link in (help codebook) means that there is a system help file for the codebook command. This is what we are interested in right now.

What is displayed is typical for help for a Stata command. Help files for Stata commands contain, from top to bottom, these features:
For now, either click on Jump to and choose Examples from the drop-down menu or scroll down to the examples. It is worth going through the examples as given in the help file. Here is a screenshot of the top of the examples:

Search is designed to help you find information about statistics, graphics, data management, and programming features in Stata, either as part of the official release or as community-contributed features. When entering topics for the search, use appropriate terms from statistics, etc. For example, you could enter Mann-Whitney. Multiple topic words are allowed, for example, regression residuals.
When you are using Search, use proper English and proper statistical terminology. If you already know the name of the Stata command and want to go directly to its help file, select Help > Stata command… and type the command name. You can also type the command name in the Search field at the top of the Viewer and press Enter.
Help distinguishes between topics and Stata commands because some names of Stata commands are also general topic names. For example, logistic is a Stata command. If you choose Stata command… and type logistic, you will go right to the help file for the command. But if you choose Search… and type logistic, you will get search results listing the many Stata commands that relate to logistic regression.
Remember that you can search for help from within a Viewer window by typing a command in the command box of the Viewer or by clicking the magnifying glass button to the right of the search box, selecting the scope of your search, typing the search criteria in the search box, and pressing Enter.
As you might expect, the help system is accessible from the Command window. This feature is especially convenient when you need help on a particular Stata command. Here is a short listing of the various commands you can use:
See [U] 4 Stata’s help and search facilities and [U] 4.8 search: All the details in the User’s Guide for more information about these command-language versions of the help system. The search command, in particular, has a few capabilities (such as author searches) that we have not demonstrated here.
All the Stata reference manuals come as PDF files and are included with the software. The manuals themselves have many cross-references in the form of clickable links, so you can easily read the documentation in a nonlinear way.
Many of the links in the help files point to the PDF manuals that came with Stata. It is worth clicking on these links to read the extensive information found in the manuals. The Stata help system, though extensive, contains only a fraction of the information found in the manuals.
Most Stata reference manuals are each arranged alphabetically. Each Getting Started with Stata has its own index. A combined index for all other manuals can be found in the Stata Index. This combined index is a good place to start when you are looking for information about a command.
Entries have names like collapse, egen, and summarize, which are generally themselves Stata commands.
Notations such as [R] ci, [R] regress, and [R] ttest in the Search results and help files are references to the Base Reference Manual. You may also see things like [P] PyStata integration, which is a reference to the Programming Reference Manual, and [U] 12 Data, which is a reference to the User’s Guide. For a complete list of manuals and their shorthand notations, see Cross-referencing the documentation, which immediately follows the table of contents in this manual.
For advice on how to use the reference manuals, see [GSW] 18 Learning more about Stata, or see [U] 1.2 The User’s Guide and the Reference manuals.
The Stata YouTube channel is an excellent resource for learning about Stata. The brief videos demonstrate many topics using Stata’s graphical user interface. They cover basic topics, such as data management, graphics, summary statistics, and hypothesis testing, and advanced topics, such as multilevel models and structural equation models.
There are also several playlists that provide a series of videos about a topic in sequence. For example, the “Power and sample size calculations” playlist includes videos about how to calculate power, sample size, and effect size for two independent proportions and for paired samples. The “Survival analysis” playlist takes you through the process of setting your data up for survival analysis, conducting basic descriptive analysis of survival data, graphing survival data, and calculating survivor functions and life tables. The “Time series” playlist takes you through the process of setting your data up for time-series analysis, creating time-series graphs, using time-series operators in estimation, and fitting ARMA and ARIMA models. There is even a “Back-to-school video” playlist for students who are using Stata for the first time or want a refresher after summer break.
See https://www.stata.com/links/video-tutorials/ for an up-to-date list of videos organized by topic. The playlists can be accessed directly at https://www.youtube.com/user/statacorp/.
When searching in Stata, you will often see links to the Stata Journal.
The Stata Journal is a printed and electronic journal, published quarterly, containing articles about statistics, data analysis, teaching methods, and effective use of Stata’s language. The Journal publishes peer-reviewed papers together with shorter notes and comments, regular columns, tips, book reviews, and other material of interest to researchers applying statistics in a variety of disciplines. The Journal is a publication for all Stata users, both novice and experienced, with different levels of expertise in statistics, research design, data management, graphics, reporting of results, and Stata, in particular. See https://www.stata-journal.com for more information.
Associated with each issue of the Stata Journal are the programs and datasets described therein. These programs and datasets are made available for download and installation over the Internet, not only to subscribers but also to all Stata users. See [R] net and [R] sj for more information.
Because the Stata Journal has had several articles about measures of inequality, if you select Help > Search…, choose Search documentation and FAQs, type inequality, and scroll down a bit, you will see some of these references:

SJ-18-3 refers to volume 18, number 3 of the Stata Journal. st0539 refers to the package name; st indicates that this package is in the “statistics” category of the Stata Journal. Listed next is the title of the software package and the authors. The community-contributed commands found within this package are listed next in parentheses, followed by the reference details of the article. Clicking on an SJ link, such as SJ 18(3):692—715, will open a browser and take you to the Stata Journal website, where you can view the abstract of the article and purchase the article. The search listing concludes with a brief description of the community-contributed package.
The Stata Journal website allows all articles older than three years to be downloaded for free. See Downloading community-contributed commands in [GSW] 19 Updating and extending Stata— Internet functionality for more details on how to install community-contributed software. Also see [R] ssc for information on a convenient interface to resources available from the Statistical Software Components (SSC) Archive.
We recommend that all users subscribe to the Stata Journal. See [U] 3.4 The Stata Journal for more information.
Links to other sites where you can freely download programs and datasets for Stata can be found on the Stata website; see https://www.stata.com/links/.
Source: STATA (2021), Getting Started with Stata for Windows, Stata Press Publication.
The post Getting help in Stata appeared first on HKT Consultant.
]]>The post Finding and Installing New Commands or User-Written Programs in Stata appeared first on HKT Consultant.
]]>If you know the name of the program you want to use, you can go directly to Installing User-Written Programs. However, it’s much more common to know what you want to do without knowing what program (if any) can do it. This is a job for Stata’s findit command.
For example, suppose you wanted to diagnose the collinearity of some variables, and you know that collin command can do it. So, type:
findit collin

The result is a tremendous amount of information. You can click on each package to view a very brief description for selecting the suitable package, for example here package st 0004 2.

If you identified the package you can install it by clicking on its link, namely “click here to install”, for example package st0004_2 above for collin command.
Now, the collin command is ready to use.
You must only type the right command for using it as we try here the collin command, for indicating the collinearity diagnostics of some variables in Stata.
If you know the name of the package you want to install, for example the package ice, you can install it by typing:
ssc install ice
The package ice with tis commands is now ready to use.


While few user-written programs are updated as frequently as ice, it’s still important to get the latest versions of any user-written programs you install. And, the easiest way to automatically update all of your user-written programs is to type:
adoupdate, update

The latest versions of all of your user-written programs are now updated.
The post Finding and Installing New Commands or User-Written Programs in Stata appeared first on HKT Consultant.
]]>The post Opening and saving Stata datasets appeared first on HKT Consultant.
]]>A Stata dataset can be opened in a variety of ways, most of which are probably familiar to you from other applications:
Opening a dataset in the current frame will replace the dataset, if any, that is currently in memory for that frame. Datasets in other frames are unaffected. If there have been changes to the data in the dataset in the current frame, Stata will refuse to discard the dataset unless you force it to do so. If you open the file with any method other than the Command window, you will be prompted. If you use the Command window and the current data have changed, you will get the following error message:
. sysuse auto
no; dataset in memory has changed since last saved
r(4);
These behaviors protect you from mistakenly losing data.
To save an unnamed dataset (or an old dataset under a new name):
To save a dataset for use with Stata 13,
To save a dataset that has been changed (overwriting the original data file),
Once you overwrite a dataset, there is no way to recover your original dataset. With important datasets, you may want to either keep a backup copy of your original filename.dta or save your changes to a dataset under a new name. This is no different from working with a word-processing document, except that recovering from an inadvertent save of a dataset is nearly impossible.
Important note: Changes you have made to a dataset are not permanent until you save them. You work with a copy of the dataset in memory, not with the data file itself. This should not be surprising, because it is the way that you work with almost all applications on your computer.
If you do not want to save your dataset, you can clear the dataset in memory and open a new dataset by typing use filename, clear.
Source: STATA (2021), Getting Started with Stata for Windows, Stata Press Publication.
The post Opening and saving Stata datasets appeared first on HKT Consultant.
]]>The post Using the Data Editor in Stata appeared first on HKT Consultant.
]]>The Data Editor gives a spreadsheet-like view of data that are currently in memory. You can use it to enter new data, edit existing data, search through the dataset, and edit attributes of the data in the dataset, such as variable names, labels, and display formats, as well as value labels.
In addition to the view of the data, there are two windows for manipulating variables and their properties: the Variables window and the Properties window. These are similar to the same-named windows in the main Stata window.
Any action you take in the Data Editor results in a command being issued to Stata as though you had typed it into the Command window. This means that you can keep good records and learn commands by using the Data Editor.
The Data Editor can be kept open while you work in Stata, giving you a live view of your dataset as you work. To protect your data from inadvertent changes, the Data Editor has two modes: edit mode for active editing and browse mode for viewing. In browse mode, editing within the Data Editor window is disabled. We highly recommend that you use the Data Editor in browse mode and switch to edit mode only when you want to make changes.
You can print your data from the Data Editor by selecting Print from the File menu.
We will be entering and editing data in this chapter, as well as manipulating the variables by using the Variables and Properties windows, so start the Data Editor in edit mode by clicking on the Data
Editor (Edit) button, PI.
The toolbar for the Data Editor has some standard buttons and some buttons we have not yet seen:
![]()
Edit mode: Changes the Data Editor to edit mode.
Browse mode: Changes the Data Editor to browse mode for safely looking at data.
Open: Opens a Stata dataset. Stata will warn you if your current dataset has unsaved changes.
Save: Saves the dataset visible in the Data Editor.
Print: Prints the dataset visible in the Data Editor.
Copy: Copies the current selection to the Clipboard.
Paste: Pastes the contents of the Clipboard. You may paste only if one cell is selected—this Cs cell will become the upper-left corner of the pasted contents. Warning: This action will paste over existing data.
Find: Opens the Find bar for searching in the Data Editor.
Filter observations: Filters the observations visible in the Data Editor. This button is useful for looking at a subset of the current dataset.
You can move about in the Data Editor by using the typical methods:
You can also click within a cell to select it.
Right-clicking within the Data Editor brings up a contextual menu that allows you to manipulate the data and what you are viewing. Right-clicking on the Data Editor window displays a menu from which you can do many common tasks:
Entering data into the Data Editor is similar to entering data into a spreadsheet. One major difference is that the Data Editor has the concept of observations, which makes the data entry smart. We will illustrate this with an example. It will be useful for you to follow the example at your computer. To work along, you will need to start with an empty dataset, so save your dataset if necessary, and then type clear in the Command window.
Note: As a check to see if your data have changed, type describe, short (or d,s for short). Stata will tell you if your data have changed.
Suppose that we have the following data, and we want to enter them into Stata:

We do not know MPG for the third car or the make of the sixth.
Start by opening the Data Editor in edit mode. You can do this either by clicking on the Data
Editor (Edit) button, PI, or by typing edit in the Command window. You should be greeted by a Data Editor with no data displayed. (If you see data, type clear in the Command window.) Stata shows the active cell by highlighting it and displaying varname[obsnum] next to the input box in the Cursor Location box. We will see below that we can navigate within a dataset by using this cell reference. The Data Editor starts, by default, in the first row of the first column. Because there are no data, there are no variable names, and so Stata shows var1[1] as the active cell.
We can enter these data either by working across the rows (observation by observation) or by working down the columns (variable by variable). To enter the data observation by observation, press Tab after entering each value until you have reached the end of the first row. In our case, we would type VW Rabbit, press Tab, type 4697, press Tab, and continue entering data to complete the first observation.
After you are finished with the first observation, select the second cell in the first column, either by clicking within it or by navigating to it. At this point, your screen should look like this:

We can now enter the data for the second observation in the same fashion as the first—with one nice difference: after we enter the last value in the row, pressing the Tab key will bring us to the first cell in the third row. This is possible because the number of variables is known after the first observation has been entered, so Stata knows when it has all the data for an observation.
We can enter the rest of the data by pressing the Tab key between entries, simply skipping over missing values by tabbing through them.
If we had wanted to enter the data variable by variable, we could have done that by pressing Enter between each make of car until all seven observations were entered, skipping past the missing entry by pressing Enter twice. Once the first variable was entered, we would select the first cell in the second column and enter the price data. We would continue this until we were finished.
There are several things to note about data entry and the feedback you get from the Data Editor as you enter data:
Whenever you enter new variables or observations, always begin in the first empty column or row. If you skip columns or rows, Stata will fill in the intervening columns or rows with missing values.
To help distinguish between the different types of variables in the Data Editor, string values, value labels (see [GSW] 9 Labeling data), and all other values are displayed in different colors. You can change the colors for strings and value labels by right-clicking on the Data Editor window and selecting Preferences…………
Stata has a system missing value, ‘.’, and extended missing values ‘.a’ through ‘.z’. By default, Stata uses its system missing value.
As we saw above, after the first observation has been entered, Stata knows how many variables you have. So at the end of the second observation (and all subsequent observations), Tab will automatically take you back to the first column.
The Cursor Location box gives the location of the current cell. If you see, for example, var3[4], this means that the current cell is the fourth observation of the variable named var3. You can navigate to a particular cell by typing the variable name and the observation in the Cursor Location box. If you wanted the second observation of varl to be the active cell, typing varl 2 in the Cursor Location box and pressing Enter would take you there.
Once Stata knows that a variable is a string variable (it holds text), there is no need to put quotes around the values, even if the values look like a number. Thus, if you wanted to enter ZIP codes as text, you would enter the first ZIP code with quotes (“02173”), but the rest would not need any quotes.
If you select a cell and type new data, using an arrow key will accept the change and move to a new active cell. If you double-click on a cell, you can edit within the cell contents. In this case, the right- and left-arrow keys move within the cell’s data.
If, while you are entering data in a cell, you decide you would like to cancel the changes, press the Esc key or click outside the cell.
The data have now been entered into Stata, but the variable names leave something to be desired: they have the default names varl, var2, …, var5. We would like to rename the variables so that they match the column titles from our dataset. We would also like to give the variables descriptions and change their formatting.
We will step through changing the name, label, and format of the price variable. We will then add a note to the variable. Start by clicking on the var2 variable in the Variables window. The few properties associated with var2 are now visible and editable in the Properties window. We may now systematically change the properties of var2 to our choosing:
To edit the properties of another variable, click on the variable in the Variables window. We can name the first variable make; the third, mpg; the fourth, weight; and the fifth, gear_ratio. Just before you rename var5 to gear_ratio, your screen should look like this:

You need to know some rules for variable names:
Make, make, and MAKE are all different names to Stata. If you had named your variables Make, Price, MPG, etc., then you would have to type them correctly capitalized in the future. Using all lowercase letters is easier.
For more information about variable names and value labels, see [GSW] 9 Labeling data; for display formats, see [U] 12.5 Formats: Controlling how data are displayed.
You can copy and paste data by using the Data Editor. This is often a simple way to bring data into Stata from any other applications such as spreadsheets or databases.
We will illustrate copying and pasting an observation by making a copy of the first observation and pasting it at the end of the dataset.
Start by clicking on the observation number of the first observation. Doing so highlights all the data in the row. Right-click on the same location (there is no need to move the mouse), and select Copy:

Click on the first cell in the eighth row, right-click while you are still in that cell, and choose Paste from the resulting menu. You can see that the observation was successfully duplicated.
As its name suggests, the Data Editor can be used to edit your dataset. As we have seen already, it can be used to edit the data themselves as well as the description and display options for the variables.
Here is an example for making some changes to the automobile dataset, which illustrates both methods for using the Data Editor and its documentation trail. We will also keep snapshots of the dataset as we are working so that we can revert to previous versions of the dataset in case we make a mistake.
We would like to investigate the dataset, work with value labels, delete the trunk variable, and make a new variable showing gas consumption per 100 miles. These tasks will illustrate the basics of working in the Data Editor.
Start by typing sysuse auto into the Command window. If you worked the previous example, you will get an error and are told that the dataset in memory has changed since it was last saved. This is good—Stata is keeping you from inadvertently throwing away the unsaved changes to your current dataset as it loads auto.dta. If you would like to save the dataset you have been working on, select File > Save and save the dataset in an appropriate location. Otherwise, type clear in the Command window, and press Enter to clear out the data, and then load that auto.dta.
Once auto.dta is loaded, start the Data Editor.

If you have something else, you can edit the label by clicking on the Edit label button.
Now that the label has been created, attach it to the rep78 variable by clicking on the down arrow in the Value label field and selecting the repairs label. You can now see the labels displayed in place of the values.
Throughout this data-editing session, we have been using the Data Editor to manipulate the data. If you look in the Results window, you will see the commands and their output. You can also see all the commands generated by the Data Editor in the History window. If you wanted to save the editing commands to use again later, you could do the following steps:
This procedure will save all the commands you highlighted into the Do-file Editor. You could then save them as a do-file, which you could run again later. We will talk more about the Do-file Editor in [GSW] 13 Using the Do-file Editor—automating Stata. You can find help about do-files in [U] 16 Do-files.
If you want to save this dataset, save it under a new name by using File > Save as… in the main Stata window to prevent overwriting the original dataset.
The Data Editor allows you to save to disk snapshots of whatever dataset you are working on. These are temporary copies of the dataset—they will be deleted when you exit Stata, so they need to be treated as temporary. Still, there are many uses for snapshots, such as
We will keep using auto.dta from above; if you are starting here, you can start fresh by typing sysuse auto in the Command window to open the dataset. (If you get a warning about data in memory being lost, either use clear or save your data. See [GSW] 5 Opening and saving Stata datasets for more information.) If we open the Data Editor and click on the Snapshots tab beneath the Variables window, we see the following window. If you are starting afresh, you will see numbers rather than labels for rep78.

To begin with, only one button is active in the Snapshots toolbar. Click on the active button—the
Add button,
. It brings up a dialog asking for a label, or name, for the snapshot. Give it an inventive name, such as Start, and press Enter. You can see that a snapshot is now listed in the Snapshots window, and all the buttons in the toolbar are now active. The following buttons appear in the Snapshots window:
Add: Save a new snapshot with a timestamp and label.
Remove: Erase a snapshot. This action deletes the temporary snapshot file but does not affect the data in memory.
Change label: Edit the label of the selected (highlighted) snapshot.
Restore: Replace the data in memory with the data from the selected snapshot. You will get a dialog asking you to confirm your action.
You should now try manipulating the dataset by using the tools we have seen. Once you have done that, create another snapshot, calling it Changed. Open the Snapshots window and restore the Start snapshot by either double-clicking it or clicking first on it and then on the Restore button to see where you started. You can then go back to where you were working by restoring your Changed snapshot.
Snapshots continue to be available either until they are deleted or until you exit Stata. You can thus use snapshots of one dataset while working on another. You will find your own uses for snapshots—just take care to save the datasets you want for future use because the snapshots are temporary.
The Data Editor has two special tools for working with dates in Stata. To see these in action, we will need to open another dataset. Either save your dataset or clear it out, and then type sysuse sp500 in the Command window. Look in the Data Editor to see what you have.

You can see a date variable that has January 2, 2001, as its first day, though it is being displayed in Stata’s default format for dates.
We will start with formatting:
This is a very simple way to change date formats. For complete information on dates and date formats, see [D] Datetime.
We will now change some of the dates to illustrate how this can be done simply, regardless of the format in which the dates are displayed. If you look in the upper-right corner of the Data Editor, you will see the Time/Date input mask field, which shows DMY. This field affects how dates are entered when editing data.
By default, the input mask is set to DMY. This means dates can be entered in many different fashions, as long as the order of the date components is day, month, year. Try the following:
Working in this fashion is the fastest way to edit dates by hand. If you look in the Results window, you will see why.
We are now finished with this dataset, so type clear and press Enter.
As you could see above, a small mistake in the Data Editor could cause large problems in your dataset. You really must take care in how you edit your data.
We would now like to investigate restricting our view of the data we see in the editor. This feature is useful for the reasons mentioned above, and as we will see, it helps if we would like to browse through the data of a large dataset. In any case, we would like to focus on some data, not all the data, whether we focus on some of the variables, some of the observations, or even just some observations within some variables. We would also like to change the order of the variables. We will show you how this is done by using both the graphical interface and commands.
Open the automobile dataset by typing sysuse auto. If you get an error message, type clear and try again. Once you have done that, open the Data Editor.
Suppose that we would like to edit only those observations for which rep78 is missing. We will need to look at the make of the car so that we know which observations we are working with, but we do not need to see any other variables. We will work as though we had a very large dataset to work with.
If you look in the Command window, you can see that no commands have been issued, because hiding the variables does not affect the dataset—it affects only what shows in the Data Editor.
We now have protected ourselves by using only those variables that we need. We should now reduce our view to only those observations for which rep78 is missing. This is simple.
Now we are focused on the part of the dataset in which we would like to work, and we cannot destroy or mistakenly alter other data by stray keystrokes in the Data Editor window.
It is worth learning how to hide variables and filter observations in the Data Editor from the Command window. This can be quite convenient if you are going to restrict your view, as we did above. To work from the Command window, we must use the edit command together with a varlist (variable list) along with if and in qualifiers in the Command window. By using a varlist, we restrict the variables we look at, whereas the if and in qualifiers restrict the observations we see. ([GSW] 10 Listing data and basic command syntax contains many examples of using a command with a variable list and if and in.) Suppose we want to correct the missing values for rep78. The minimum amount of data we need to expose are make and rep78. To see this minimal amount of information and hence to minimize our exposure to making mistakes, we enter the commands

and we would see the following window:

Once again, we are safe and sound.
Keep this lesson in mind if you edit your data. It is a lesson well learned.
The purpose of using the Data Editor in browse mode is to look at data without altering them by stray keystrokes. You can start the Data Editor in browse mode by clicking on the Data Editor
(Browse) button,
, or by typing browse in the Command window. When you work in browse mode, all contextual menu items that would let you alter the data, the labels, or any of the display formats for the variables are disabled. You may view a variable’s properties with the Properties menu item, but you may not make any changes. You still can filter observations and hide variables to get a restricted view because these actions do not change the dataset.
Note: Because you can still use Stata menus not related to the Data Editor and because you can still type commands in the Commands window, it is possible to change the data even if the Data Editor is in browse mode. In fact, this means you can watch how your commands affect the dataset. You are merely restricted from using the Data Editor itself to change the data.
Source: STATA (2021), Getting Started with Stata for Windows, Stata Press Publication.
The post Using the Data Editor in Stata appeared first on HKT Consultant.
]]>The post Using the Variables Manager in Stata appeared first on HKT Consultant.
]]>This chapter discusses Stata’s Variables Manager. To get started, open the automobile dataset by typing sysuse auto, clear in the Command window. You open the Variables Manager by selecting Data > Variables Manager or clicking on the Variables Manager button
.

The Variables Manager is a tool for managing properties of variables both individually and in groups. It can be used to create variable and value labels, rename variables, change display formats, and manage notes. It has the ability to filter and group variables as well as to create variable lists. Users will find these features useful for managing large datasets.
Any action you take in the Variables Manager results in a command being issued to Stata as though you had typed it in the Command window. This means that you can keep good records and learn commands by using the Variables Manager.
The left pane of the Variables Manager is called the Variable pane, though it has no explicit title on the screen. It shows the list of variables in the dataset. This list can be manipulated in a variety of ways.
The sort order affects only how the data appear in the Variable Managers window—the dataset itself stays the same.

Right-clicking on the Variable pane displays a menu from which you can do many common tasks:
The Variable Properties pane can be used to manipulate the properties of variables selected in the Variable pane. With one variable selected, you can manipulate all properties of the variable. With many variables selected, you can change their formats or types as well as assign value labels all at once. These fields work in the same fashion as those shown in Renaming and formatting variables in [GSW] 6 Using the Data Editor. We can also manage the notes Stata allows you to attach to variables and the dataset—we will show an example below.
The Variable Properties pane is, in actuality, a docking window, like those discussed in Auto Hide and pinning in [GSW] 2 The Stata user interface. You can see this because of the pushpin in its upper-right corner. If you click on the pushpin, the window will automatically hide when not in use. You can also dock the window in another part of the Variables Manager window by dragging it by its title bar to one of the docking guides.
Stata allows you to attach notes to both variables and the dataset as a whole. These are simple text notes that you can use to document whatever you like—the source of the dataset, data collection quirks associated with a variable, what you need to investigate about a variable, or anything else.
Start by selecting a variable in the Variable pane. We will work with the price variable. Click on the Manage… button next to the Notes field, and you will see the following dialog appear:

We will add a few notes:

It is worth experimenting with adding, deleting, and editing notes. Notes can be an invaluable memory aid when working on projects that last a long time. Anytime you manipulate notes in the Notes Manager, you create Stata commands.
Source: STATA (2021), Getting Started with Stata for Windows, Stata Press Publication.
The post Using the Variables Manager in Stata appeared first on HKT Consultant.
]]>