---
title: "Trade vs Output Perspectives: Comparing BM 2023 and BM 2025"
author: "gvcAnalyzer Package"
date: "`r Sys.Date()`"
output:
  rmarkdown::html_vignette:
    toc: true
    toc_depth: 3
    number_sections: true
vignette: >
  %\VignetteIndexEntry{Trade vs Output Perspectives: Comparing BM 2023 and BM 2025}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 5
)

library(gvcAnalyzer)
```

# Introduction

The **gvcAnalyzer** package implements two complementary frameworks for measuring global value chain (GVC) participation:

1. **Trade-Based** (BM 2025 Trade): Decomposition of gross exports.

2. **Output-Based** (BM 2025 Output): Decomposition of gross production.

This vignette compares these approaches, demonstrating when each measure is most appropriate and how they provide complementary insights into GVC integration.

## References

Borin, A., & Mancini, M. (2023). Measuring What Matters in Global Value Chains and Value-Added Trade. *Journal of International Economics*.

Borin, A., & Mancini, M. (2025). Measuring What Matters in Value-Added Trade: An Output-Based Approach. *Working Paper*.

# Conceptual Framework

## Trade-Based Approach (BM 2025 Tripartite)

The trade-based framework decomposes **gross exports** from country *s* to country *r* into GVC components:

- **DAVAX**: Traditional trade (domestic value added absorbed abroad in one crossing)

- **GVC\_PF**: Pure-forward GVC (domestic value added re-exported by the partner)

- **GVC\_TS**: Two-sided GVC (both foreign inputs and re-export linkages)

- **GVC\_PB**: Pure-backward GVC (foreign value added in exports)

**Key feature**: Measures how much of a country's **exports** participate in GVCs.

## Output-Based Approach (BM 2025 Output)

The output-based framework decomposes **gross output** of country *s* into production components:

- **DomX**: Purely domestic production (value never crossing borders)

- **TradX**: Traditional one-crossing trade

- **GVC\_PF\_X**: Pure-forward GVC-related output

- **GVC\_TS\_X**: Two-sided GVC-related output

- **GVC\_PB\_X**: Pure-backward GVC-related output

**Key feature**: Measures how much of a country's **production** is GVC-related, regardless of export destination.

## Fundamental Differences

| Dimension | Trade-Based | Output-Based |
|-----------|----------------------|----------------------|
| **Unit of analysis** | Gross exports | Gross output |
| **Focus** | Border-crossing flows | Production structure |
| **Scope** | Export transactions | Total production |
| **Captures** | Export intensity in GVCs | Comprehensive GVC involvement |
| **Best for** | Trade policy analysis | Industrial policy analysis |

# Empirical Comparison

## Data and Setup

```{r}
io <- bm_build_io(
  Z = bm_toy_Z,
  Y = bm_toy_Y,
  VA = bm_toy_VA,
  X = bm_toy_X,
  countries = bm_toy_countries,
  sectors = bm_toy_sectors
)
```

## Computing Both Frameworks

### Trade-Based Measures

```{r}
trade_meas <- bm_2025_trade_measures(io)
trade_meas[, c("exporter", "share_GVC_trade", "share_PF_trade",
               "share_TS_trade", "share_PB_trade", "forward_trade")]
```

### Output-Based Measures

```{r}
out_meas <- bm_2025_output_measures(io)
out_meas[, c("country", "share_GVC_output", "share_PF_output",
             "share_TS_output", "share_PB_output", "forward_output")]
```

## Direct Comparison

To compare the two frameworks, we merge the key indicators:

```{r}
# Standardize column names
trade_meas$country <- trade_meas$exporter

comparison <- merge(
  trade_meas[, c("country", "share_GVC_trade", "forward_trade")],
  out_meas[, c("country", "share_GVC_output", "forward_output")],
  by = "country"
)

comparison
```

### Interpretation

- **share\_GVC\_trade**: Share of exports in GVCs

- **share\_GVC\_output**: Share of production in GVCs

- **forward\_trade**: Export-based forward orientation (positive = upstream supplier)

- **forward\_output**: Production-based forward orientation

# Visualization

## GVC Participation: Trade vs Output

```{r}
oldpar <- par(mar = c(5, 5, 3, 2))

plot(
  comparison$share_GVC_trade,
  comparison$share_GVC_output,
  pch = 19,
  col = "darkblue",
  cex = 1.5,
  xlab = "GVC Share of Exports (Trade)",
  ylab = "GVC Share of Output (Output)",
  main = "Trade-Based vs Output-Based GVC Participation",
  xlim = c(0, max(comparison$share_GVC_trade, comparison$share_GVC_output, na.rm = TRUE) * 1.1),
  ylim = c(0, max(comparison$share_GVC_trade, comparison$share_GVC_output, na.rm = TRUE) * 1.1)
)

text(
  comparison$share_GVC_trade,
  comparison$share_GVC_output,
  labels = comparison$country,
  pos = 3,
  cex = 0.8
)

abline(a = 0, b = 1, lty = 2, col = "gray", lwd = 2)

grid()

par(oldpar)
```

## Forward Orientation: Trade vs Output

```{r}
oldpar <- par(mar = c(5, 5, 3, 2))

plot(
  comparison$forward_trade,
  comparison$forward_output,
  pch = 19,
  col = "darkgreen",
  cex = 1.5,
  xlab = "Forward Index - Exports",
  ylab = "Forward Index - Output",
  main = "Forward Orientation: Trade vs Production Perspective",
  xlim = c(-1, 1),
  ylim = c(-1, 1)
)

text(
  comparison$forward_trade,
  comparison$forward_output,
  labels = comparison$country,
  pos = 3,
  cex = 0.8
)

abline(h = 0, v = 0, lty = 2, col = "gray")

abline(a = 0, b = 1, lty = 2, col = "red", lwd = 2)

grid()

par(oldpar)
```

# Summary

This vignette demonstrated the **complementarity** of trade-based and output-based GVC measures.

- **Trade-based measures** are ideal for export competitiveness and trade policy.

- **Output-based measures** are ideal for industrial policy and sectoral analysis.

- **Both together** provide the most comprehensive assessment of GVC integration.

For robust empirical research on global value chains, we recommend computing both frameworks and interpreting results in light of their complementary strengths.

# Session Information

```{r}
sessionInfo()
```
