Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Data Analysis with STATA
Data Analysis with STATA

Data Analysis with STATA: Explore the big data field and learn how to perform data analytics and predictive modelling in STATA

eBook
$20.98 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Data Analysis with STATA

Chapter 2. Stata Programming and Data Management

This chapter will showcase the labeling methodology of the variables in Stata. It is really important to understand the data management aspects of Stata, which are covered in depth in this chapter. We will cover the following topics:

  • The labeling of the data, variables, and variable transformations
  • Summarizing the data and preparing tabulated reports
  • Appending and merging the files for data management

The labeling of data, variables, and variable transformations

Stata is easy to use and gives you the leverage point of labeling different variables in the data you have acquired/imported. It also allows you to:

  • Label the dataset itself
  • Label different value signs in the imported dataset
  • Label various variables in the imported dataset

For example, let's assume that we have a dataset with no labels. The name of the dataset/filename is Fridge_sales.

You can leverage Stata functions and commands and do not have to write code from the beginning.

To get details of the current dataset (Fridge_sales), type the following command in Stata:

describe

Here is the output of this command:

The labeling of data, variables, and variable transformations

Now, you can leverage a command called label data so that you can add the label that can describe the dataset in detail. The label of the dataset can have a maximum length of 80 characters. To label the data, use the following command:

label data "This dataset has fridge sales data from year 2000"

As discussed...

Summarizing the data and preparing tabulated reports

Now, we will use the Fridge_sales data for further commands. For this, you need to inform Stata that you will be using Fridge_sales_data with the following command:

use fridge_sales_data

Now, in this data, the variables' volume denotes the volume of the fridge. How do you generate this variable in Stata? Your answer lies in using the summarize command:

summarize volume

The output of this command is as follows:

Summarizing the data and preparing tabulated reports

Now, you need to create a new variable called volume_ratio. The volume ratio denotes the fridge volume divided by 20:

generate volume_ratio = volume / 20

The generate command creates new variables in the given dataset. Similarly, for existing variables that need to be treated and made perfect for further analysis, you can use the replace command:

For example, take a look at the following:

replace volume = volume / 20

Now, you can see the changes between the original variable and the derived variable using the summarize command:

summarize...

Appending and merging the files for data management

Now, let's discuss how to work with more than one file. We will create two data files and combine them in different ways.

Let's create the first data file in Stata:

input fridge_model_id str10 model cost
1 "model 1" 12000
2 "model 2" 20000
3 "model 3" 40000
End
Save fridge_model, replace
List
Appending and merging the files for data management

Let's create the second dataset:

Clear
Input fridge_model_id str10 model cost
1 "model 4" 42000
2 "model 5" 52000
3 "model 6" 62000
End
Save fridge_model2, replace
List
Appending and merging the files for data management

Now, let's append the two files we created:

Appending and merging the files for data management
use fridge_model, clear
append using fridge_model2
Appending and merging the files for data management

Now, let's take the fridge_model data that has been prepared and sort it by fridge_model_id:

use fridge_model, clear
sort fridge_model _id
save fridge_model3
list
Appending and merging the files for data management

Let's create the second dataset for these models:

clear
input fridge_model_id str10 length width
1 100 200
2 150 300
3 200 400
end

sort fridge_model_id...

Macros

A Stata macro is not a black box where we can input the text and numbers. You can use this module or box in various commands. One of the best tricks in Stata is to leverage many macro statements or, as they are rightly called, modules or boxes in a single Stata command and optimize the entire code.

First, let's look at local macros. If you are an experienced programmer, you might know the difference between global variables and local variables. This difference remains in Stata as well. Most of the macros in Stata are local macros and are written for specific commands or functions that can be reused for many occasions. For example, take a look at the following command:

local macro_Name table

For example:

local Y 9

In this command or macro, the name of the macro is Y and 9 is the denotation of the table. Another example can be as follows:

display "Y"

On a general note, all the macros are processed by the macro processor. The macro processor properly feeds the macros to Stata...

Loops in Stata

Loops is a very important concept in Stata. For various calculations and executions, putting code into loops is an extremely useful concept. The command used to create loops in Stata is foreach. The syntax for such a command is as follows:

foreach macro_name in list_name {
command(s)
}

Now, let's take a small example:

Foreach ball_size in ten twenty thirty [
display " 'ball_size' "
]

In this code, ball_size acts as the name of the written macro. It has a list of the elements that need to be part of the macro. Stata's macro processor breaks this list into appropriate sections. In this case, the sections of the current code can be as per the element list, such as ten, twenty, and thirty.

The brackets denote the beginning and the ending of the loop:

  • [: This denotes the beginning of the loop
  • ]: This denotes the end of the loop

The Stata macro processor analyzes the entire list, which is your input in the macro statement. It also identifies all the elements...

The labeling of data, variables, and variable transformations


Stata is easy to use and gives you the leverage point of labeling different variables in the data you have acquired/imported. It also allows you to:

  • Label the dataset itself

  • Label different value signs in the imported dataset

  • Label various variables in the imported dataset

For example, let's assume that we have a dataset with no labels. The name of the dataset/filename is Fridge_sales.

You can leverage Stata functions and commands and do not have to write code from the beginning.

To get details of the current dataset (Fridge_sales), type the following command in Stata:

describe

Here is the output of this command:

Now, you can leverage a command called label data so that you can add the label that can describe the dataset in detail. The label of the dataset can have a maximum length of 80 characters. To label the data, use the following command:

label data "This dataset has fridge sales data from year 2000"

As discussed previously in...

Left arrow icon Right arrow icon

Description

STATA is an integrated software package that provides you with everything you need for data analysis, data management, and graphics. STATA also provides you with a platform to efficiently perform simulation, regression analysis (linear and multiple) [and custom programming. This book covers data management, graphs visualization, and programming in STATA. Starting with an introduction to STATA and data analytics you’ll move on to STATA programming and data management. Next, the book takes you through data visualization and all the important statistical tests in STATA. Linear and logistic regression in STATA is also covered. As you progress through the book, you will explore a few analyses, including the survey analysis, time series analysis, and survival analysis in STATA. You’ll also discover different types of statistical modelling techniques and learn how to implement these techniques in STATA.

Who is this book for?

This book is for all the professionals and students who want to learn STATA programming and apply predictive modelling concepts. This book is also very helpful for experienced STATA programmers as it provides advanced statistical modelling concepts and their application.

What you will learn

  • Perform important statistical tests to become a STATA data scientist
  • Be guided through how to program in STATA
  • Implement logistic and linear regression models
  • Visualize and program the data in STATA
  • Analyse survey data, time series data, and survival data
  • Perform database management in STATA

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 28, 2015
Length: 176 pages
Edition : 1st
Language : English
ISBN-13 : 9781782173175
Category :
Concepts :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Oct 28, 2015
Length: 176 pages
Edition : 1st
Language : English
ISBN-13 : 9781782173175
Category :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 121.97
Mastering Text Mining with R
$43.99
Data Analysis with STATA
$38.99
Getting Started with Python Data Analysis
$38.99
Total $ 121.97 Stars icon

Table of Contents

10 Chapters
1. Introduction to Stata and Data Analytics Chevron down icon Chevron up icon
2. Stata Programming and Data Management Chevron down icon Chevron up icon
3. Data Visualization Chevron down icon Chevron up icon
4. Important Statistical Tests in Stata Chevron down icon Chevron up icon
5. Linear Regression in Stata Chevron down icon Chevron up icon
6. Logistic Regression in Stata Chevron down icon Chevron up icon
7. Survey Analysis in Stata Chevron down icon Chevron up icon
8. Time Series Analysis in Stata Chevron down icon Chevron up icon
9. Survival Analysis in Stata Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.2
(5 Ratings)
5 star 0%
4 star 40%
3 star 0%
2 star 0%
1 star 60%
Sampada May 30, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
As a strategy consultant, this book helped a lot to understand analytics concepts in simple language. The book is very good in explaining tough analytics methods in simple language. I have tried many ways to learn analytics and could not get beyond jargons. I really liked this book because of simple, straightforward language with good real life examples.
Amazon Verified review Amazon
SD Nov 10, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Really liked the simple language and easy examples used to explain some complex analytics concepts. I am using Stata on healthcare and genome data and this book helped me a lot.
Amazon Verified review Amazon
Alexander Huelle Sep 02, 2016
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Da alle Titel, die ich bisher von Packt Publishing gelesen hatte, sehr gut waren, bestellte ich auch dieses Buch. Leider fehlt es ihm an so ziemlich allem, was ein gutes Buch ausmacht:- es ist ausgesprochen schlampig lektoriert. Nicht nur sind viele Schreibfehler stehen geblieben, bei einem Bild wurde sogar die Dummy-Darstellung nicht ersetzt.- die Darstellung der Themen enthält deutliche Lücken und Sprünge, die das Verständnis sehr erschweren- die Auswahl der Themen erscheint willkürlich und auch für einen Überblick zu fragmentarisch.Insgesamt: nicht empfehlenswert!.
Amazon Verified review Amazon
Amazon Customer Jan 25, 2017
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
you're better off using another book as this one is too primitive and not helpful at all.
Amazon Verified review Amazon
Christopher Bratt Apr 01, 2016
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Not a very detailed book. But much more important, I've never before seen a book with so many typos. Some of them will make learning Stata rather difficult.Two examples:1."A Stata macro is not [sic] a black box where we can input [sic] the text and numbers."2.After using a correct template for foreach loops (with curly brackets), the text goes on to consistently using square brackets for denoting the beginning and the end of the loop.Added later:I looked throught the rest of the book. It's a complete waste of your money and time. Even if you disregard the many typos (assuming they were corrected): You will learn very little about Stata reading this book.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.