Julia: Tutorial & Code-Collection¶
Source: https://github.com/markomlikota/CodingSoftware
MIT License, © Marko Mlikota, https://markomlikota.github.io
Created: September 2025. Last updated: September 2025
Introduction¶
Julia is just amazing, for several reasons.
- First, it uniquely combines the ease of high-level languages (like e.g. R, Matlab, Python) with the performance of low-level compiled code.
- Second, its computational efficiency translates into energy-efficiency: see Pareira et al. (2017) and Stewart et al. (2025) for efficiency comparisons, some of which indicate Julia outperforms alternatives like Python in terms of efficiency by a factor of 40!
- Third, Julia is an open-source language (like R and Python and in contrast to Matlab), which means that it is accessible to researchers and practitioners regardless of institutional resources or geographic location and that one can use many state-of-the-art methods provided as packages by programmers from all over the world.
- Finally, like many other languages (e.g. R, Matlab, Python) but in contrast to, say, Stata or EViews, it is very flexible, which allows you to easily implement methods, approaches and procedures that deviate from standard ones and are tailored to your specific needs.
This script is meant to introduce you to Julia and to collect useful commands for different programming tasks in one place. As such, it can be used as a lookup-table. Even people experienced with a programming language regularly consult google or previously written codes as part of their coding routine, even more so when they haven't used a programming language for a while or when switching back and forth between several languages. Not surprisingly, then, you won't memorize much when going through this tutorial. It is only through experience that one can learn a programming language well. Nevertheless, this tutorial should facilitate the first steps.
Each of the following sections is self-contained. You'll get most out of the tutorial by writing the commands you see here by yourself on your computer, running them, having a look at the results, and implementing simple changes to the code to see how the output changes. Most of the code can be ran, but a few parts of the code are included only for illustration purposes; they cannot be ran since the necessary objects are not defined (e.g. some folder, dataset or excel-file).
You can download and install Julia from https://julialang.org/downloads/.*
To work efficiently with Julia, download and install Visual Studio Code (not Visual Studio!) from https://visualstudio.microsoft.com/downloads/. VS Code is an editor, with which one can write, store and execute Julia code (akin to the editor RStudio commonly used to work with the software R).
To configure Julia on VS Code, go to Code>Settings>Extensions, and install the extension “julialang”. Once installed, the extension should automatically locate Julia on your computer. To verify whether it worked for you, open a new file, store it as “myFirstJuliaCode.jl” (the extension .jl will tell VS Code that the file is code written for Julia), type the following few lines into it --
a = 3
b = 4
a/b
a*b
-- and execute it either by highlighting the whole text and pressing shift+enter or by clicking on the play button on the top right. In case VS Code did not find Julia automatically, go to Code>Settings>Extensions and read the instructions on how to locate Julia manually by specifying the path to it.
You can execute Julia-code by writing directly into the REPL ("read-evaluate-print loop")-window, located in VS Code by default at the bottom-right. However, this should be done for simple commands only and/or for experimentation. Longer codes that you would like to re-use should be written in the script-window on the top-left, as it can be stored as an .jl-file for later re-use. The script (or parts thereof) can be ran to preduce output in the REPL and in the plot-pane, located in VS Code by default on the top-right. To run a whole script, you can click on the "Play"-button on the top-right of the script-window. On a Mac, you can you can do so even easier by selecting the code you'd like to run and pressing shift+enter (to select the whole script, click cmd+a).
*Downloading Julia manually from this page works for both Mac- and Windows-users, though for Mac users it would be recommended to install Julia in a way that will make updates much easier to carry out, without the need to repeat all the steps mentioned above to install a new version: see https://julialang.org/install/. In that case, the subsequent instructions listed here may need additional steps before Julia can be used on VS Code.