• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Analysis Factor

The Analysis Factor

Statistical Consulting, Resources, and Statistics Workshops for Researchers

  • Home
  • About
    • Our Programs
    • Our Team
    • Our Core Values
    • Our Privacy Policy
    • Employment
    • Guest Instructors
  • Membership
    • Statistically Speaking Membership Program
    • Login
  • Workshops
    • Online Workshops
    • Login
  • Consulting
    • Statistical Consulting Services
    • Login
  • Free Webinars
  • Contact
  • Login

Creating Graphs in Stata: From Percentiles to Observe Trends (Part 2)

by Jeff Meyer Leave a Comment

by Jeff Meyer, MPA, MBA

In a previous post we discussed the difficulties of spotting meaningful information when we work with a large panel data set.

Observing the data collapsed into groups, such as quartiles or deciles, is one approach to tackling this challenging task.  We showed how this can be easily done in Stata using just 10 lines of code.

As promised, we will now show you how to graph the collapsed data.

There are two commands for graphing panel data in Stata. Stata created the command xtline. The command profileplot was created by a third party.  The command xtline has more options and as a result creates more professional graphs.

To use xtline  the data must be in long format.  To use profileplot the data needs to be in long format. We will use the xtline command.

So the first step is to reshape the data from wide to long. We will use the percentile variable “ptl” as the identifier. We will extract “wage” from each variable containing wage data (wage1985, wage1986 etc). This variable is known as the “stub”.  The data in every variable that contains the stub “wage” in its name is transferred into the new variable “wage”.

Next, we decide on a name for the new variable that will contain whatever is to the left of “wage” in the variables containing wage data. In this case it will contain the years 1985, 1986 etc.

Wide format Long format
image001 image002

Here is the coding for reshaping from wide to long:

reshape long wage, i(ptl) j(year)

Now we have to tell Stata which variable is the “identifier” and which variable is “time”.

xtset ptl year

All that is left is creating the graph:

xtline wage, overlay title(Income by Deciles) ylabel(, angle(horizontal))              ///
note("note:Wages adjusted by CPI")  ///
legend( order(1 "10th ptl" 2 "20th ptl" 3 "30th ptl" 4 "40th ptl" 5 "50th ptl" 6 "60th ///
ptl" 7 "70th ptl" 8 "80th ptl" 9 "90th ptl") ) ///
plot1opts(lwidth(medthick)) plot2opts(lwidth(medthin)) plot3opts(lwidth(medthick))  ///
plot4opts(lwidth(medthin)) plot5opts(lwidth(medthick)) plot6opts(lwidth(medthin))  ///
plot7opts(lwidth(medthick)) plot8opts(lwidth(medthin)) plot9opts(lwidth(medthick))  ///
legend(on cols(3))

Several options were used.  The number of columns and the text in the legend were changed. For visual effects, the widths of the lines in the graph were staggered between medium and medium thin. A title at the top and notes at the bottom of the graph were also added.

image003

Jeff Meyer is a statistical consultant with The Analysis Factor, a stats mentor for Statistically Speaking membership, and a workshop instructor. Read more about Jeff here.

Tagged With: collapsed data, graphs, long, percentiles, Stata, trends, wide

Related Posts

  • Converting Panel Data into Percentiles to Observe Trends in Stata (Part 1)
  • Argggh! How Do I Output Tables and Graphs From Stata?
  • Statistical Software Access From Home
  • Member Training: What’s the Best Statistical Package for You?

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Please note that, due to the large number of comments submitted, any questions on problems related to a personal study/project will not be answered. We suggest joining Statistically Speaking, where you have access to a private forum and more resources 24/7.

Primary Sidebar

Free Webinars

Effect Size Statistics on Tuesday, Feb 2nd

This Month’s Statistically Speaking Live Training

  • January Member Training: A Gentle Introduction To Random Slopes In Multilevel Models

Upcoming Workshops

  • Logistic Regression for Binary, Ordinal, and Multinomial Outcomes (May 2021)
  • Introduction to Generalized Linear Mixed Models (May 2021)

Read Our Book



Data Analysis with SPSS
(4th Edition)

by Stephen Sweet and
Karen Grace-Martin

Statistical Resources by Topic

  • Fundamental Statistics
  • Effect Size Statistics, Power, and Sample Size Calculations
  • Analysis of Variance and Covariance
  • Linear Regression
  • Complex Surveys & Sampling
  • Count Regression Models
  • Logistic Regression
  • Missing Data
  • Mixed and Multilevel Models
  • Principal Component Analysis and Factor Analysis
  • Structural Equation Modeling
  • Survival Analysis and Event History Analysis
  • Data Analysis Practice and Skills
  • R
  • SPSS
  • Stata

Copyright © 2008–2021 The Analysis Factor, LLC. All rights reserved.
877-272-8096   Contact Us

The Analysis Factor uses cookies to ensure that we give you the best experience of our website. If you continue we assume that you consent to receive cookies on all websites from The Analysis Factor.
Continue Privacy Policy
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Non-necessary

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.