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
₹799.99 ₹2323.99
Paperback
₹2904.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781782173182
Category :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 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
₹4500 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 ₹400 each
Feature tick icon Exclusive print discounts
₹5000 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 ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total ₹2399.97 ₹7269.97 ₹4870.00 saved
Mastering Text Mining with R
₹3276.99
Data Analysis with STATA
₹2904.99
Getting Started with Python Data Analysis
₹2904.99
Total ₹2399.97₹7269.97 ₹4870.00 saved 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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.