1. Trang chủ
  2. » Luận Văn - Báo Cáo

Introduction to Time Series Using Stata

595 0 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Introduction to Time Series Using Stata
Tác giả Sean Beckett
Chuyên ngành Statistics
Thể loại Book
Năm xuất bản 2020
Thành phố College Station
Định dạng
Số trang 595
Dung lượng 24,92 MB
File đính kèm Sean-Becketti-Introduction-to-Time-S.zip (24 MB)

Nội dung

Well, that is inconvenient: the minimum and maximum temperatures are combined in a string variable. If we wanted to do some statistical analyses with these data, we would need to extract these values from the string and store t The strpos() function locates the position of one string in another string. We use the location of the “” character in the substr() function to extract the relevant portion of the string, then we apply the real() function to convert the string of digits to a number. Not difficult, but you have to know how

Trang 3

Introduction to Time Series Using Stata

Trang 4

Library of Congress Control Number: 2020932011

No part of this book may be reproduced, stored in a retrieval system, or transcribed, in any form or

by any means—electronic, mechanical, photocopy, recording, or otherwise—without the prior written permission of StataCorp LLC.

Stata, , Stata Press, Mata, , and NetCourse are registered trademarks of StataCorp LLC.

Stata and Stata Press are registered trademarks with the World Intellectual Property Organization of the United Nations.

NetCourseNow is a trademark of StataCorp LLC.

L 2 is a trademark of the American Mathematical Society.

AT XE

AT XE

Trang 5

1.1.1 Action first, explanation later

1.1.2 Now some explanation

1.1.3 Navigating the interface

1.1.4 The gestalt of Stata

1.1.5 The parts of Stata speech

1.2 All about data

2 Just enough statistics

2.1 Random variables and their moments

Trang 6

3 Filtering time-series data

3.1 Preparing to analyze a time series

3.1.1 Questions for all types of data

interest?

3.1.2 Questions specifically for time-series data

3.2 The four components of a time series

3.3.3 Smoothing a seasonal pattern

3.3.4 Smoothing real data

Trang 7

4.2.1 Forecasts based on EWMAs

4.2.2 Forecasting a trending series with a seasonal component

4.3 Points to remember

4.4 Looking ahead

5 Autocorrelated disturbances

5.1 Autocorrelation

5.1.1 Example: Mortgage rates

5.2 Regression models with autocorrelated disturbances

5.2.1 First-order autocorrelation

5.2.2 Example: Mortgage rates (cont.)

5.3 Testing for autocorrelation

5.3.1 Other tests

5.4 Estimation with first-order autocorrelated data

5.4.1 Model 1: Strictly exogenous regressors and autocorrelateddisturbances

5.4.2 Model 2: A lagged dependent variable and i.i.d errors

5.4.3 Model 3: A lagged dependent variable with AR(1) errors

5.5 Estimating the mortgage rate equation

5.6 Points to remember

6 Univariate time-series models

6.1 The general linear process

6.2 Lag polynomials: Notation or prestidigitation?

6.3 The ARMA model

6.4 Stationarity and invertibility

6.5 What can ARMA models do?

6.6 Points to remember

6.7 Looking ahead

7 Modeling a real-world time series

7.1 Getting ready to model a time series

Trang 8

7.2 The Box–Jenkins approach

7.3 Specifying an ARMA model

7.3.1 Step 1: Induce stationarity (ARMA becomes ARIMA)

7.3.2 Step 2: Mind your p’s and q’s

7.4 Estimation

7.5 Looking for trouble: Model diagnostic checking

7.5.1 Overfitting

7.5.2 Tests of the residuals

7.6 Forecasting with ARIMA models

8.1 Examples of time-varying volatility

8.2 ARCH: A model of time-varying volatility

8.3 Extensions to the ARCH model

8.3.1 GARCH: Limiting the order of the model

8.3.2 Other extensions

9.1.1 Three types of VARs

9.2 A VAR of the U.S macroeconomy

9.2.1 Using Stata to estimate a reduced-form VAR

9.2.2 Testing a VAR for stationarity

Trang 9

9.4.1 Examples of a short-run SVAR

9.4.2 Examples of a long-run SVAR

9.5 Points to remember

9.6 Looking ahead

10 Models of nonstationary time series

10.1 Trends and unit roots

10.2 Testing for unit roots

10.3 Cointegration: Looking for a long-term relationship

10.4 Cointegrating relationships and VECMs

10.4.1 Deterministic components in the VECM

10.5 From intuition to VECM: An example

10.6 Points to remember

10.7 Looking ahead

11 Closing observations

11.1 Making sense of it all

11.2 What did we miss?

11.2.1 Advanced time-series topics

11.2.2 Additional Stata time-series features

11.3 Farewell

References

Trang 10

Author index Subject index

Trang 11

Stata operators

Importing and exporting data

Date and time formats

Questions to answer prior to data analysis

Comparison of forecasts

Share of “respectable” forecasts

Indicators of , , and

FEVD

Trang 12

The describe dialog box

The ratio of girls to boys in primary and secondary school

Income per capita and the ratio of girls to boys in school

Log income per capita and the ratio of girls to boys in school

Log income per capita and the ratio of girls to boys in school

Population-weighted relationship between income and female education

emissions in the United States, 1990–2008

Energy use per capita in the United States (kg of oil equivalent)

The relationship between the unemployment rate and nonfarm payrollemployment, January 1950 to January 2012

U.S civilian unemployment rate, January 1948 through March 2012Average monthly prepayment rates (annualized) on seasoned FederalNational Mortgage Association 30-year discount mortgages, 2000–2007Trend (unobserved) and Trend+Residual (observed)

A span-3 median smoother and a Hanning smoother

A close-up of the outlier in month 46

Combining Hanning with a median smoother

Comparing span-3 and span-9 smoothers

Three smoothers and cyclical data

Trang 13

The span-9 median smoother performs poorly on cyclical data

Odd-span median smoothers tend to produce flat spots

The relative performance of a complex and a simple smoother

U.S civilian unemployment rate, January 1948 through March 2012

EWMA forecasts with different projection dates

DEWMA forecasts with different projection dates

EWMA and DEWMA forecast errors

One-step-ahead forecast errors for three methods

Distribution of one-step-ahead forecast errors (in tenths of a percent)

rate

Weekly currency component of M1

Currency component in recent years

Seasonal Holt–Winters forecast

Backtesting the seasonal Holt–Winters forecast

Primary and secondary mortgage rates

The spread between the primary and secondary mortgage rates

Current residuals versus lagged residuals

In-sample fit of three estimation strategies

Decay when

Comparison of trend line and Holt–Winters residuals

Comparison of trend line and Holt–Winters forecasts

Converting the linear trend to a one-step-ahead forecast

Trang 14

Autocorrelation and partial autocorrelation functions of white noise

where

1947:2 to 2012:1

The conditional variance of

Monthly and annual consumer price inflation in the United States

Conditional variance of monthly consumer inflation

U.S inflation, unemployment, and the Federal funds rate, 1960:1–2012:1Eigenvalues of the companion matrix

U.S inflation, forecasts and actuals, 2002:2–2012:1

Forecast errors of U.S inflation, 2001:2–2012:1

Forecasts of U.S inflation, unemployment, and the Federal funds rate,2001:3–2011:2

Dynamic forecasts of U.S inflation, unemployment, and the Federal fundsrate, 2002:2–2012:1

Dynamic and one-step-ahead forecasts

Cross correlations of inflation and unemployment rates, 1960:2–2001:2Cross correlations of inflation, unemployment, and the Federal funds rate

Trang 15

An example of the sensitivity of estimates to the sample period

Estimated cointegrating relationships

Autocorrelation functions of the cointegrating relationships

Orthogonalized impulse–response functions

Evolution of the cointegrating relationship

Trang 16

Welcome

Time-series analysis is a relatively new branch of statistics Most of thetechniques described in this book did not exist prior to World War II, andmany of the techniques date from just the last few decades The novelty ofthese techniques is somewhat surprising, given the importance of

forecasting in general and of predicting the future consequences of today’spolicy actions in particular The explanation lies in the relative difficulty ofthe statistical theory for time series When I was in graduate school, one of

my econometrics professors admitted that he had switched his focus fromtime series when he realized he could produce three research papers a year

on cross-section topics but only one paper per year on time-series topics

Why another book on time series?

The explosion of research in recent decades has delivered a host of

powerful and complex tools for time-series analysis However, it can take alittle while to become comfortable with applying these tools, even for

experienced empirical researchers And in industry, these tools sometimesare applied indiscriminately with little appreciation for their subtleties andlimitations There are several excellent books on time-series analysis atvarying levels of difficulty and abstraction But few of those books arelinked to software tools that can immediately be applied to data analysis

I wrote this book to provide a step-by-step guide to essential time-seriestechniques—from the incredibly simple to the quite complex—and, at thesame time, to demonstrate how these techniques can be applied in the

Stata statistical package

Why Stata? There are, after all, a number of established, powerful

statistical packages offering time-series tools Interestingly, the conventionsadopted by these programs for describing and analyzing time series varywidely, much more widely than the conventions used for cross-sectiontechniques and classical hypothesis testing Some of these packages focus

Trang 17

primarily on time series and can be used on non-time-series questions onlywith a bit of difficulty Others have to twist their time-series procedures into

a form that fits the rest of the structure of their package

I helped out in a small way when Stata was first introduced At thattime, the most frequent question posed by users (and potential users) was,

“When will time series be available?” For a long time, we would tell users(completely sincerely) that these techniques would appear in the next

release, in six to twelve months However, we repeatedly failed to deliver

on this promise Version after version appeared with many new features, butnot time series I moved on to other endeavors, remaining a Stata user butnot a participant in its production Like other users, I kept asking for time-series features—I needed them in my own research I finally became

frustrated and, using Stata’s programming capabilities, cobbled togethersome primitive Stata functions that helped a bit

Why the delay? Part of the reason was other, more time-critical

demands on what was, at the beginning, a small company However, I thinkthe primary reason was StataCorp’s commitment to what they call the

“human-machine interface” There are lots of packages that reliably

calculate estimates of time-series models Many of them are difficult to use.They present a series of obstacles that must be overcome before you cantest your hypotheses on data Frequently, it is challenging to thoroughlyexamine all aspects of your data And they make it onerous to switch

directions as the data begin to reveal their structure

Stata makes these tasks easy—at least, easy by comparison to the

alternatives I find that the facility of Stata contributes to better analyses Iattempt more, I look more deeply, because it is easy The teams that workfor me use several different packages, not just Stata, depending on the task

at hand I find that I get better, more thorough analyses from the team

members using Stata I do not think it is a coincidence

When Stata finally gained time-series capabilities, it incorporated adesign that retains the ease of use and intuitiveness that has always been thehallmark of this package That is why I use Stata rather than any of theother candidate packages

Trang 18

Despite the good design poured into Stata, time-series analysis is stilltough That is just the nature of the time-series inference task I tend tolearn new programs by picking up the manual and playing around I

certainly have learned a lot of the newer, more complex features of

Stata that way However, I do not think it is easy to learn the time-series

techniques of Stata just from reading the Stata Time-Series Reference

Manual—and it is a very well-written manual I know—I tried For a long

time, I stuck with my old, home-brew Stata functions to avoid the task oflearning something different, even after members of my staff had adoptedthe new Stata tools

Writing this book provided me with the opportunity to break out of mybad habits and make the transition to Stata’s powerful time-series features.And I am glad I did Once you come up the learning curve, I think thesetools will knock your socks off They certainly lower the barrier to manyambitious types of empirical research

I hope you are the beneficiary of my learning process I have attempted

in these pages to link theory with tools in a way that smooths the path foryou Please let me know if I have succeeded Contact the folks at Stata

Press with your feedback—good or bad—and they will pass it along to me

Why a revised edition?

The first edition of this book was written using Stata 12 The revised editionhas been updated for Stata 16 Specifically, chapter 1 includes updated

discussions of Stata’s interface, datasets, and commands for importing data.Stata’s default random-number generator (RNG) changed from the 32-bitKISS RNG to the 64-bit Mersenne Twister RNG in Stata 14 Therefore,

simulated datasets for examples in chapters 3, 5, 7, and 10 have changed.Results of these examples, and in some cases the random-number seed usedfor reproducibility, have been updated Finally, chapter 11 was updated withbrief overviews of time-series features that have been added since Stata 12

Who should read this book?

Stata users trying to figure out Stata’s time-series tools.

Trang 19

You will find detailed descriptions of the tools and how to apply themcombined with detailed examples and an intuitive explanation of thetheory underlying each tool.

Time-series researchers considering Stata for their work.

Each commercial time-series package takes a different approach tocharacterizing time-series data and models Stata’s unique approachoffers distinct advantages that this book highlights

Researchers who know a bit about time series but want to know more.

The gestalt of time-series analysis is not immediately intuitive, even toresearchers with a deep background in other statistical techniques

Researchers who want more extensive help than the manual can

provide.

It is clear and well written, but, at the end of the day, it is a manual, not

a tutorial

How is this book organized?

Like Gaul, this book is divided into three parts

Preliminaries.

Preparation for reading the rest of the book

Chapter 1: Just enough Stata.

A quick and easy introduction for the complete novice Also

useful if you have not used Stata for a while

Chapter 2: Just enough Statistics.

A cheat sheet for the statistical knowledge assumed in later

chapters

Filtering and Forecasting.

A nontechnical introduction to the basic ways to analyze and forecasttime series Lots of practical advice

Chapter 3: Filtering time-series data.

A checklist of questions to answer before your analysis The fourcomponents of a time series Using filters to suppress the randomnoise and reveal the underlying structure

Chapter 4: A first pass at forecasting.

Forecast fundamentals Filters that forecast

Time-series models.

Trang 20

Modern approaches to time-series models.

Chapter 5: Autocorrelated disturbances.

What is autocorrelation? Regression models with autocorrelation.Testing for autocorrelation Estimation with first-order

autocorrelated data

Chapter 6: Univariate time-series models.

The general linear process Notation conventions The mixedautoregressive moving-average model Stationarity and

A model of time-varying volatility Extensions to the

autoregressive conditional heteroskedasticity model

Chapter 9: Models of multiple time series.

Vector autoregressions A vector autoregression of the

U.S macroeconomy Cross correlations, causality, impulse–

response functions, and forecast-error decompositions Structuralvector autoregressions

Chapter 10: Models of nonstationary time series.

Trends and unit roots Cointegration From intuition to vectorerror-correction models

Chapter 11: Closing observations.

Making sense of it all What did we miss?

Ready, set,

I am a reporter I am reporting on the work of others Work on the statisticaltheory of time-series processes Work on the Stata statistical package toapply this theory As a reporter, I must give you an unvarnished view ofthese topics However, as we are frequently reminded in this postmodern

Trang 21

world, none of us can be completely objective, try as we will Each of ushas a perspective, a slant informed by our life experiences.

Here is my slant I was trained as an academic economist I became asoftware developer to pay my way through graduate school and found Iliked the challenges of good software design as much as I liked economicresearch I began my postgraduate career in academics, transitioned to theFederal Reserve System, and eventually ended up in research in the

financial services industry, where I have worked for a number of leadingfirms (some of them still in existence) I believe I have learned somethingvaluable at each stage along the way

For the purposes of this book, the most important experience has been

to see how statistical research, good and bad, is performed in academics, theFed, and industry Good academic research applies cutting-edge research tothorny problems Bad academic research gets caught up in footnotes andtrivia and loses sight of real-world phenomena The Federal Reserve

produces high-quality research, frequently published in the best academicjournals A signature characteristic of research within the Fed is a deepknowledge of the institutional details that can influence statistical

relationships However, Fed research occasionally exhibits an

oversimplified perspective of the workings of the financial services

industry Industry has to make decisions in real time Accordingly, industryresearch has to generate answers quickly Good industry research makeswise tactical choices and selects reasonable shortcuts around technical

obstacles Bad industry research is “quick and dirty”

Embrace the good, avoid the bad Perhaps because the latter half of mycareer has been spent in industry, my personal bent is to recognize the

limitations of the tools I use without becoming distressed over them I ammore interested in intuition than in proofs

Here are three articles that sum up the approach I try to emulate:

Diaconis, P 1985 Theories of data analysis: From magical thinking

through classical statistics In Exploring Data Tables, Trends, and

Shapes, ed D C Hoaglin, F Mosteller, and J W Tukey, 1–36 New

York: Wiley

Trang 22

Ehrenberg, A S C 1977 Rudiments of numeracy Journal of the

Royal Statistical Society, Series A 140: 277–297.

Trang 23

chapters Thank you.

The editors at Stata Press were a joy to work with, although at timeswhen I was tired, it seemed that they had too many good ideas The tightstructure of chapter 5 owes much to David Drukker’s help Brian Poi saved

me from myself more times than I can count His suggestions were

practical, reasonable, and expressed without giving any sign that he

recognized how slipshod I had been Much appreciated Also appreciated isStata Press’s patience with a very slow author In my defense, I believe Istill came in well under the time it took Stata to finally release a versionwith time series

I would like to thank the Keurig company, without whose excellentcoffee maker this book would never have been finished As I frequently tell

my staff, sleep is overrated

The Internet provided musical inspiration throughout The careful

reader should be able to detect which sections were written while listening

to Glenn Gould’s early recording of the Goldberg Variations and whichwere written while listening to AC/DC’s “Highway to Hell”

I dedicate this book to my extraordinary wife, Linda She bore the brunt

of my extended mental and physical absences for writing Without her loveand support, there would be no point to all this

Trang 25

1.2 All about data.

Getting data in Getting data out Doing things to data Seeing whatyou have

1.5 Odds and ends.

Repeating yourself Matrices Randomness

1.6 Making a date.

How Stata thinks about time series Tools for handling dates and times

1.7 Typing dates and date variables.

Literally typing a date Time-series operators

1.8 Looking ahead.

Statistical background

If you have never used Stata before, this chapter is for you Reading thischapter will not make you a Stata expert, but it will teach you just enoughStata to read the rest of this book without any trouble You will be able tofollow the examples, rerun them (using the datasets available on the

Stata Press website), and change them around however you wish

You may find this chapter helpful even if you have used Stata already,particularly if you have never used Stata’s time-series features The

treatment of time series is sufficiently different from the rest of Stata, soyou will benefit from a little extra explanation

Trang 26

Do not be daunted by the length of this chapter It’s 99.99% simpleexamples that illustrate Stata features you will encounter later in the book.

In other words, lots of pictures and no math I recommend you try out theexamples as you read along Of course, you will need access to a computerwith Stata already installed on it.1

If you do not have a copy of Stata yet, the folks at StataCorp will be glad to help

you You can order a copy and get additional information at https://www.stata.com

Trang 27

1.1 Getting started

1.1.1 Action first, explanation later

Results window, you will see

The first line is an echo of the command you typed It follows the Stata prompt,

command In this example, you asked Stata to load into memory one of the

Automobile Data)—is attached to auto.dta, and Stata displays this label as itloads the dataset The next line is blank, separating this command and its resultsfrom what comes next; finally, Stata displays the period prompt indicating that it

is ready and waiting for your next command

you see

Trang 28

Hmmm, lots of information here Seventy-four observations on twelve variables.That descriptive data label appears again near the top right There is a list ofeach of the 12 variables with indications of how Stata is storing the information,how Stata intends to format any values it displays, and a descriptive label foreach variable Finally, it appears the data are already sorted by one of the

Let’s look at the contents of a few of these variables

Those 1978 prices look pretty good

Now let’s get some simple distributional information about these data

Trang 29

The average car price is $6,165 with an average mileage of 21 MPG (but at least

There are some mysteries here How come there are no observations for the

will worry about this later For now, let’s push on

I wonder how many of the cars in this dataset are domestic and how manyare foreign

In 1978, foreign cars were actually foreign, that is, not produced in the UnitedStates Typically, they were smaller than domestic cars and got better mileage.Let’s check

Trang 30

I wonder if that difference in MPG is statistically significant.4

(last estimates not found) and a return code (r(301)) Oh, I forgot to

indicate the variable that defines the two populations Let’s see if this works

That did not work either I guess I will have to search Stata’s interactive helpsystem or read the manual I will save you that step for now and just show youwhat I should have typed

This test indicates the difference is highly significant However, this version of

Trang 31

reminder just below the ttest command) I wonder if that assumption is

appropriate

the test But this did not change the answer much

I mentioned that foreign cars tended to be smaller than domestic cars in

than the country of manufacture

Trang 32

Graphs by Car type

Figure 1.1: The relationship between automobile mileage and automobile

weight

This could go on forever, but by now, you should have a feel for what a Statasession is like We will stop playing with data for a bit and start explaining Stata

in more detail

1.1.2 Now some explanation

You start Stata the same way you start any other program on your computer Inother words, the way you start Stata depends on the computer you use I useStata on a Windows computer at work and on a Mac at home I use Stata

frequently enough that I have its icon in the program tray at the bottom of thescreen on my Windows computer Sometimes I forget and start Stata the old-

fashioned way—by clicking on the Start button in the lower left corner of the

screen and clicking through until I find Stata

On my Mac, I start Stata by clicking on the Stata icon on the Dock I couldalso start Stata by using Finder to navigate to Stata in the Applications folder,then double-clicking on the Stata icon

1.1.3 Navigating the interface

Trang 33

What you see next depends on your computer and whether someone has

configured the appearance of Stata in any special way The five main windowsare the History, Results, Command, Variables, and Properties windows Thelargest window is the Results window, and it is stacked on top of the smallCommand window The third window, labeled History, appears as a sidebar onthe left The Variables and Properties windows are stacked as a sidebar to the

Figure 1.2: Stata for Windows opening screen

As you have probably already guessed, you type your commands in theCommand window, and the results of your commands appear in the Resultswindow (Graphs appear in a separate Graph window More on that later.)

Stata/MP 16 If you are using a different version, the name of your version willappear instead The Stata menu appears below the title bar The menu begins

with some familiar choices: File, Edit, Data, Graphics, Statistics, User,

Window, and the ever-popular Help The Stata menu provides an easy way to

learn Stata Virtually everything that Stata can do can be done through the menu

Trang 34

system We will provide some examples in a bit, but let’s finish looking at

figure 1.2 first

The toolbar at the top of the Stata window displays several icons At the left

of the toolbar, there are three icons: open a file (which can contain a

Stata dataset, a script of Stata commands, and a few other types of things), savethe dataset you are using currently, and print your results

The next seven icons are the following:

Log

opens a submenu for starting, stopping, and viewing log files, that is,

records of your Stata session

opens a window for editing a script of Stata commands These scripts end

Command window

Data Editor

opens a window that looks a bit like a spreadsheet The Data Editor

provides a convenient tool for editing the dataset currently in use You canadd variables, drop variables, add observations, change the values of

individual observations, and change the names or other properties of

variables

Data Browser

is a “safe” version of the Data Editor You can view, but not change, yourdata As a convenience, you can switch between edit and browse modes atany time in both the Data Editor and the Data Browser

Variables Manager

opens a window for managing the properties of variables

There are two remaining icons—a circle with a down arrow labeled “Showmore results” and an “X” icon labeled “Break” By default, Stata will not pause

in its display of results You can tell Stata to pause once the screen is full by

Trang 35

typing set more on in the Command window Clicking on the More icon tells

Stata you are done reading the current screen and you are ready for more Youcan also tell Stata to display another screenful of output by pressing (almost) any

key If you press the Return key, Stata will display one additional line of output

rather than a screenful Clicking on the Break icon will interrupt Stata and return

control to you—very handy when you have accidentally generated a lot more

output than you expected And, yes, there are keyboard shortcuts for Break as

well, but they vary by computer type Try what usually works for you On my

Mac, I use Command- (that is, I hold down the Command key while pressing the period key).

From the Help menu, Stata provides a search feature to easily access Stata’s vast documentation system To access this search feature, click on Help from the

menu and then select Search For instance, click on the Search all radio button

(or whatever it’s called on your keyboard) A Viewer window that looks

Trang 37

Figure 1.3: Viewer window displaying search results

In this example, Stata searched for the keyword “regress” in 1) the official

help files, videos, blog post, frequently asked questions, examples, and the Stata

Journal and 2) web resources from Stata and other users The results returned by

the search command are quite extensive, and the screenshot displays only a

fraction of them The third item in the results list is an entry from the Stata Base

Reference Manual that describes the regress command If you click on thehighlighted word “regress” in that listing, the viewer will display the help file forthe regress command You can search for things more complicated than specific

command in the Command window rather than typing a keyword in the search

mental note to come back to these screens when you get stuck Because thischapter is intended to provide you just enough Stata to get started, I frequently

As I mentioned above, almost every Stata command can be launched fromthe menu system Let’s look at one example On the menu bar, click on the word

Data The Data menu will drop down The first item is Describe data Click on

Trang 38

Figure 1.4: Data menu

Click on the item Describe data in memory or in a file You should see a

Trang 39

Figure 1.5: The describe dialog box

Press Return or click on OK, and you will see the following in the Results

window:

Stata prompt, the indication that Stata is ready for you to type another

command.) In this case, Stata tells you that you have no observations and novariables in your dataset yet

From the screenshots, you can see that there are many commands to manageyour data and many options within those commands to give you minute controlover your data (Click on some other commands to see what the dialog boxes

Trang 40

offer.) Some users rely on the menu system for all their work in Stata Others usethe menu system as a set of “training wheels” for Stata: they use the menu

system to familiarize themselves with the commands they need, then start typingthe commands directly in the Command window, relying on the menu systemonly for unfamiliar commands as they gain experience Both approaches workfine You should use the approach that suits you best I am old fashioned; I typeall my commands in the Command window When I need to learn about an

need But that is just my style

Before we go any further, you should learn how to end a Stata session Yourcomputer probably has methods for exiting programs, and you can use those

the dataset in Stata and you have not saved a copy yet, Stata will refuse to exit.The Results window will display the following information:

last saved and a return code (r(4);) For now, the only thing you need to learnfrom the return code is that Stata would not carry out your command If you do

will exit without a complaint

Now you can start and stop a Stata session, and you can find your way

around the user interface We are just about ready to dig into the details of Stata,but before we do, I would like to give you some tips that make it easier to

understand Stata

1.1.4 The gestalt of Stata

All programs have a certain logic to them, a preferred way of operating, andStata is no exception Once you get the hang of Stata’s view of the world, usingStata and learning new features is easy Here are some simple things to

remember:

Stata is designed as an interactive program.

Ngày đăng: 26/03/2024, 08:02

w