Skip to main content

Implementing Convex Optimization in R: Two Econometric Examples


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, access via your institution.


  1. 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. 2.

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


  1. 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 

  2. 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.

  3. 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 

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

    Google Scholar 

  5. 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.

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

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

  8. 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 

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

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

    Article  Google Scholar 

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

    Article  Google Scholar 

  12. 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 

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

    Article  Google Scholar 

  14. 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 

  15. 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 

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

    Article  Google Scholar 

  17. 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 

  18. 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



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

Verify currency and authenticity via CrossMark

Cite this article

Gao, Z., Shi, Z. Implementing Convex Optimization in R: Two Econometric Examples. Comput Econ (2020).

Download citation


  • Big data
  • Convex optimization
  • High-dimensional model
  • Numerical solver

JEL Classification

  • C13
  • C55
  • C61
  • C87