Skip to content

Commit

Permalink
typo in gd_functions and md_functions welfare shares examples added
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiacek committed Feb 14, 2024
1 parent 40508fb commit 3b6cb46
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion vignettes/gd_functions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ When `complete = FALSE`, the output is a list. The results can be accessed like

```{r popshare-results}
# Format the string with the given values
formatted_message <- sprintf("%.0f%% of the population owns %.0f%% of welfare.",
formatted_message <- sprintf("The bottom %.0f%% of the population owns %.0f%% of welfare.",
selected_popshare * 100,
welfare_share_50$dist_stats$welfare_share_at[[1]] * 100)
Expand Down
55 changes: 50 additions & 5 deletions vignettes/md_functions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ It also provides a series of functions to calculate distributional measures and

- `pipmd_quantile()`

- `pipmd_validate_lorenz()`

- `pipmd_select_lorenz()`

## Micro Data Sample

In this vignette, we will explore several typical scenarios in which the pipster package can be effectively utilized. In each of these scenario, we will use a sample dataset with 1000 observations, `pip_md`, available with this package. The variables are the following:
Expand Down Expand Up @@ -144,7 +140,7 @@ The Gini coefficient can be calculated using `pipmd_gini()` like so:
gini <- pipmd_gini(welfare = pip_md$welfare,
weight = pip_md$weight)
print((paste0("The gini index is ", round(gini$value,2))))
print((paste0("The gini index is ", round(gini$value, 2))))
```

The Watts Index can be calculated using `pipgd_watts()` like so:
Expand All @@ -163,3 +159,52 @@ mld <- pipmd_mld(welfare = pip_md$welfare,
print((paste0("The MLD is ", round(mld$value,2))))
```

## Case 3: Welfare Shares

### 3.1 Welfare share for a specific number of quantiles

One simple use case is the calculation of welfare shares at a specific quantile or the cumulative welfare shares at a specific quantile by specifying `n`:

```{r welfare-quantiles}
quantiles <- 5
quantile_welfare_share <- pipmd_quantile_welfare_share(welfare = pip_md$welfare,
weight = pip_md$weight,
n = quantiles)
quantile_welfare_share_at <- pipmd_welfare_share_at(welfare = pip_md$welfare,
weight = pip_md$weight,
n = quantiles)
# Combine into a dataframe for practicality
df_combined <- data.frame(
popshare = quantile_welfare_share$quantile,
quantile_share = quantile_welfare_share$share,
cumulative_share = quantile_welfare_share_at$share_at
)
# View the combined dataframe
print(df_combined)
```
### 3.2 Welfare share at a given population share

Another use case is calculating the welfare share of a specific share of the population, which can be achieved using `pipmd_welfare_share_at()` by setting `n = NULL` and specifying the `popshare`:

```{r welfare-popshare}
selected_popshare <- 0.8
welfare_at_50 <- pipmd_welfare_share_at(welfare = pip_md$welfare,
weight = pip_md$weight,
n= NULL,
popshare = selected_popshare)
# Format the string with the given values
formatted_message <- sprintf("The bottom %.0f%% of the population owns %.0f%% of welfare.",
selected_popshare * 100,
welfare_at_50$share_at * 100)
print(formatted_message)
```




0 comments on commit 3b6cb46

Please sign in to comment.