8
$\begingroup$

Quick question (but complex answer) : R or Python ?

I work as an economist/Strategist in the finance industry. As I do a lot of presentations, notes-writing, data searching, my programming time is limited but we try to develop “small scale” models to answer economic/finance questions. So, I mainly do standard stuff such as PCA/factor models SVAR with sign restrictions, VECM…I usually use what tools is best suited for the job (if I find replication codes I can adapt for instance), so usually MATLAB for SVARs and factor analysis, Eviews for quick and dirty stuff…

Now, I am looking at Python and R (which I dabbled with a few years go). Python is broader and I could use it for other stuff (like automate boring stuff with a comp or an iPad) but it seems there are fewer pure econometrics packages than in R (did not find anything for SVAR with sign restrictions for instance). I am looking to extract data from the web as well, and although they both seem to be able to do that, Python, seems more suited right ?

I know there is always the possibility of calling one from the other (with like Rpy) but then you need to learn both languages. Any advice ?

Thanks!

$\endgroup$
  • 2
    $\begingroup$ The correct answer is "yes." $\endgroup$ – Carl Witthoft May 26 at 12:34
14
$\begingroup$

If you already know how to code in MATLAB then python is more similar to it than R so I would say you will have easier time to transitioning there.

Otherwise, both R and Python are programming languages so you will be able to do all those things in both of them as you can always program your own functions.

The strength of R is that the language has a large following in the research community, which then in turn means that people write a lot of packages that focus on exactly the models that are commonly used in research. For more than two decades academics and statisticians basically helped to develop R so you can now find library for anything there save for really the most cutting edge econometric techniques - and you can bet that the first place where those will get their packages will be R. For most of the things you describe in your post you will have some excellent libraries and they are relatively more easier to estimate with R than with Python.

Python is more of an general purpose programming language which strength is very intuitive syntax. Writing in Python can sometimes feel like writing in pseudo code - its very intuitive and natural. However, since its more general purpose language its not as tailored to statistical analysis as R. You will definitely be able to do all you want to do there but more routine statistical analysis will be a bit more time consuming to code.

I actually prefer using R for any standard statistical analysis and Python for numerical analysis & machine learning & mining data through web-scraping.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Having learned some Matlab after having worked with R (a lot) and Pyhton (less), I disagree on Matlab being more similar to Python than to R. Matlab and R have in common vectorized operations, and that makes coding in both very similar, at least when programming simple numeric analysis algorithms. However, your mileage may vary. $\endgroup$ – Pere May 26 at 16:51
6
$\begingroup$

I would like to add on to the previous post from 1muflon1. Total agree with the post and I will try not to repeat anything said but I feel there is some additional information that is worth mentioning about both R and Python.

When it comes to loops

Python is faster than R, when the number of iterations is less than 1000. Below 100 steps, python is up to 8 times faster than R. However, when you use the R lappy function R will be faster. R programming has language evolve over time.
https://datascienceplus.com/loops-in-r-and-python-who-is-faster/

Data visualizations and Maps

R provides some basic packages that are installed by default. This includes the graphics package, which contains about 100 functions to create traditional plots. These very simple functions will allow you to quickly create scatterplots, boxplots, and histograms. This comes in handy for quick data exploration.

Unlike R, Python does not include data visualization tools by default. However, Python also provides many libraries like Matplotlib and Seaborn for this purpose. Python now also offers numerous packages which are equivalents of ggplot2 in R. The most commonly used library for data visualization in Python is Matplotlib.

Geospatial Maps

When it comes to geospatial maps R is the software to use. As far as mapping capabilities with python, they are a bit limited. However, python code is used for qgis and arcmap. It can be very powerful but you need to really, really know the code and what you are doing to be able to take advantage.

At the end of the day both software’s are good but I invite you to ask yourself these questions before you get started.

  1. What problems do you want to solve and what tasks do you need to accomplish?
  2. What are the commonly used tools in your field?
  3. What language are your colleagues using?
| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ Using R's data.table for working with large datasets also gets you very far in terms of speed/efficiency. $\endgroup$ – Kenneth Rios May 25 at 22:05
  • 1
    $\begingroup$ The benchmark article you link suffers from bad programming. R's speed is sensitive to memory pre-allocation (as is any language). By simply pre-allocating the result's vec (as is implicitly done by lapply()) you will get an immense increase in speed. I'm not sure how this is realised in Python. $\endgroup$ – thorepet May 26 at 9:07
  • 2
    $\begingroup$ Some reproducible and regularly updated data processing benchmarks for R, Python and others: h2oai.github.io/db-benchmark $\endgroup$ – Gregory Demin May 26 at 10:18
  • 1
    $\begingroup$ "R provides some basic packages that are installed by default." Python has a lot of basic packages built-in as well, the rest are easily installed and if you really want something complete to start with, there's Anaconda. $\endgroup$ – Mast May 26 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.