Stata command to draw a graph showing the average of a variable by group

Suppose we have the following dataset that provides the life expectancy (lexp) of each country in each region:

We can draw a bar graph to show the average (or other statistics) life expectancy of each region using two different methods:

Method 1: using the collapse command

Method 2: using the egen tag command

Method 1 will actually destroy the original data. If we need to keep the original data available for use afterward, Method 2 may be more convenient.

This entry was posted in Stata and tagged . Bookmark the permalink.

2 Responses to Stata command to draw a graph showing the average of a variable by group

  1. Ed says:

    Very helpful. Thanks, Kai!

  2. Nik says:

    what if we want the mean by two groups (e.g. firm and year) in a panel data?

Leave a Reply

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