Skip to main content
Log in

Implementing Convex Optimization in R: Two Econometric Examples

  • Published:
Computational Economics Aims and scope Submit manuscript


Economists specify high-dimensional models to address heterogeneity in empirical studies with complex big data. Estimation of these models calls for optimization techniques to handle a large number of parameters. Convex problems can be effectively executed in modern programming languages. We complement Koenker and Mizera (J Stat Softw 60(5):1–23, 2014)’s work on numerical implementation of convex optimization, with focus on high-dimensional econometric estimators. Combining R and the convex solver MOSEK achieves speed gain and accuracy, demonstrated by examples from Su et al. (Econometrica 84(6):2215–2264, 2016) and Shi (J Econom 195(1):104–119, 2016). Robust performance of convex optimization is witnessed across platforms. The convenience and reliability of convex optimization in R make it easy to turn new ideas into executable estimators.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.


  1. At the writing of this note, CVXR + MOSEK takes from minutes to hours to compute one estimation depending on sample sizes, which makes the full-scale simulation exercise computational infeasible.

  2. CVXR + MOSEK does not support exponential/logarithm objective functions and hence is infeasible for REL.


  • Bajari, P., Nekipelov, D., Ryan, S. P., & Yang, M. (2015). Machine learning methods for demand estimation. American Economic Review, 105(5), 481.

    Article  Google Scholar 

  • Chen, W., Chen, X., Hsieh, C.-T., & Song, Z. (2019). A forensic examination of China’s national accounts. Brookings Papers on Economic Activities Spring, 77–127.

  • Diamond, S., & Boyd, S. (2016). CVXPY: A python-embedded modeling language for convex optimization. Journal of Machine Learning Research, 17(83), 1–5.

    Google Scholar 

  • Domahidi, A., Chu, E., & Boyd, S. (2013). ECOS: An SOCP solver for embedded systems. European Control Conference (ECC), 2013, 3071–3076.

    Google Scholar 

  • Doudchenko, N., & Imbens, G. W. (2016). Balancing, regression, difference-in-differences and synthetic control methods: A synthesis. Technical report, National Bureau of Economic Research No. 22791.

  • Fu, A., Balasubramanian, N., & Boyd, S. (2019). CVXR: An R package for disciplined convex optimization. Journal of Statistical Software, arxiv:1711.07582.

  • Grant, M., & Boyd, S. (2014). CVX: Matlab software for disciplined convex programming, version 2.1.

  • Gu, J., & Koenker, R. (2017). Empirical bayesball remixed: Empirical bayes methods for longitudinal data. Journal of Applied Econometrics, 32(3), 575–599.

    Article  Google Scholar 

  • Johnson, S. G. (2017). The nloptnonlinear-optimization package.

  • Koenker, R., & Bassett, G. (1978). Regression quantiles. Econometrica, 46, 33–50.

    Article  Google Scholar 

  • Koenker, R., & Mizera, I. (2014). Convex optimization in R. Journal of Statistical Software, 60(5), 1–23.

    Article  Google Scholar 

  • Nash, J. C., & Varadhan, R. (2011). Unifying optimization algorithms to aid software system users: optimx for R. Journal of Statistical Software, 43(9), 1–14.

    Article  Google Scholar 

  • Shi, Z. (2016). Econometric estimation with high-dimensional moment equalities. Journal of Econometrics, 195(1), 104–119.

    Article  Google Scholar 

  • Su, L., & Ju, G. (2018). Identifying latent grouped patterns in panel data models with interactive fixed effects. Journal of Econometrics, 206(2), 554–573.

    Article  Google Scholar 

  • Su, L., & Lu, X. (2017). Determining the number of groups in latent panel structures with an application to income and democracy. Quantitative Economics, 8(3), 729–760.

    Article  Google Scholar 

  • Su, L., Shi, Z., & Phillips, P. C. (2016). Identifying latent structures in panel data. Econometrica, 84(6), 2215–2264.

    Article  Google Scholar 

  • Su, L., Wang, X., & Jin, S. (2019). Sieve estimation of time-varying panel data models with latent structures. Journal of Business & Economic Statistics, 37(2), 334–349.

    Article  Google Scholar 

  • Ypma, J. (2017). nloptr: R interface to NLopt R package version 1.0.4.

Download references


Shi thanks Roger Koenker for inspiration and hospitality during his visit to University of Illinois.

Author information

Authors and Affiliations


Corresponding author

Correspondence to Zhentao Shi.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Gao, Z., Shi, Z. Implementing Convex Optimization in R: Two Econometric Examples. Comput Econ 58, 1127–1135 (2021).

Download citation

  • Accepted:

  • Published:

  • Issue Date:

  • DOI:


JEL Classification