7  For Stata users

In this example, the package functions are combined in such a way that the results obtained are more or less familiar to those users who are accustomed to using Stata.

7.1 Set up

Import the package.

library(paneldesc)

7.2 Data import

Import the built-in dataset with simulated unbalanced panel data.

data(production)

7.3 summarize

You can look at the simple descriptive statistics with summarize_numeric().

summarize_numeric(production)
Analyzing all numeric variables: firm, year, sales, capital, labor
variable count mean std min max
firm 180 15.500 8.680 1.000 30.000
year 180 3.500 1.713 1.000 6.000
sales 154 68.402 45.025 11.999 292.850
capital 154 33.152 32.044 2.030 160.085
labor 154 76.883 74.150 5.972 579.024

7.4 xtset

You can set up a panel structure in advance so that you don’t have to do it later each time you use other functions. Note that if delta is supplied, the function checks for omitted time periods. If such periods exist, they will be taken into account when other functions work with this argument.

panel <- make_panel(production, index = c("firm", "year"), delta = 1)

7.5 xtdes

xtdes command functionality can be reproduced by combining describe_dimensions(), describe_balance(), and describe_patterns() functions.

describe_dimensions(panel)
rows entities periods variables
180 30 6 6
describe_balance(panel, detail = TRUE)
dimension mean std min p5 p25 p50 p75 p95 max
entities 26.167 3.971 19 20.5 25.25 27 28.75 29.75 30
periods 5.233 0.935 3 4.0 4.25 6 6.00 6.00 6
describe_patterns(panel)
pattern 1 2 3 4 5 6 count share
1 1 1 1 1 1 1 16 0.533
2 1 1 1 1 1 0 5 0.167
3 1 1 1 1 0 0 3 0.100
4 0 0 1 1 1 1 2 0.067
5 0 1 1 1 1 0 2 0.067
6 0 1 1 1 1 1 1 0.033
7 1 1 1 0 0 0 1 0.033

7.6 xtsum

xtsum command functionality can be reproduced with decompose_numeric() function.

decompose_numeric(panel)
Analyzing all numeric variables: sales, capital, labor
variable dimension mean std min max count
sales overall 68.402 45.025 11.999 292.850 154.000
sales between NA 29.060 34.263 166.364 30.000
sales within NA 34.127 -12.444 234.297 5.133
capital overall 33.152 32.044 2.030 160.085 154.000
capital between NA 17.414 9.019 74.225 30.000
capital within NA 27.072 -25.567 149.329 5.133
labor overall 76.883 74.150 5.972 579.024 154.000
labor between NA 41.068 31.021 190.645 30.000
labor within NA 61.202 -58.040 483.217 5.133

7.7 xttab

xttab command functionality can be reproduced with decompose_factor() function.

decompose_factor(panel)
Analyzing all factor variables: industry, ownership, region
variable category count_overall share_overall count_between share_between share_within
industry Industry 1 63 0.401 13 0.433 0.918
industry Industry 2 45 0.287 11 0.367 0.809
industry Industry 3 49 0.312 10 0.333 0.917
ownership private 80 0.510 17 0.567 0.894
ownership public 36 0.229 9 0.300 0.787
ownership mixed 41 0.261 10 0.333 0.772
region west 38 0.242 7 0.233 1.000
region east 40 0.255 8 0.267 1.000
region north 36 0.229 7 0.233 1.000
region south 43 0.274 8 0.267 1.000

7.8 xttrans

xttrans command functionality can be reproduced with summarize_transition() function.

summarize_transition(panel, select = "industry")
23 rows with NA values in 'industry' removed.
from_to Industry 1 Industry 2 Industry 3
Industry 1 1.000 0.000 0.000
Industry 2 0.054 0.919 0.027
Industry 3 0.000 0.025 0.975

7.9 reshape

reshape command functionality can be reproduced with make_wide() and make_long() functions.

wide <- make_wide(panel, select = c("sales", "capital", "labor", "industry", "ownership"))
  Static variables: region 
Reshaped variables: sales_1, sales_2, sales_3, sales_4, sales_5, sales_6 
                    capital_1, capital_2, capital_3, capital_4, capital_5, capital_6 
                    labor_1, labor_2, labor_3, labor_4, labor_5, labor_6 
                    industry_1, industry_2, industry_3, industry_4, industry_5, industry_6 
                    ownership_1, ownership_2, ownership_3, ownership_4, ownership_5, ownership_6 
long <- make_long(wide, select = c("sales", "capital", "labor", "industry", "ownership"))
  Static variables: region 
Reshaped variables: sales, capital, labor, industry, ownership 

7.10 xtdata

xtdata command functionality can be partially reproduced with make_demeaned() function. Particularly, xtdata, fe is reproduced by passing only firm identifier to the function.

firm_demeaned <- make_demeaned(production, group = "firm")
Demeaning numeric variables: year, sales, capital, labor

Unlike Stata command, make_demeaned() allows you to demean variables not only within entities, but using various grouping patterns. For example, when data frame has panel attributes, it will be demeaned using both entities and time identifiers. Grouping by more than two variables is also available.

firm_year_demeaned <- make_demeaned(panel)
Demeaning numeric variables: sales, capital, labor

xtdata, be and xtdata, re functionality is not reproduced directly. However, with some additional efforts, xtdata, be can be replicated with make_mundlak() and summarize_numeric() as both these functions allow to calculate within-group means.