## Julia Essentials

; We add ; to suppress output returned. For example let’s compare two codes with and without ; at the end. x=2 would return 2 in the console as an output while x=2; will not return anything in the console. enumerate() enumerate() returns both the index and the value of an element in an array. collect(enumerate(countries)) Output: (1, "Korea") (2, "Japan") (3, "China") countries = ("Korea", "Japan", "China") for (index, country) in enumerate(countries) println("Country $(country) in index$(index)") end Output:...

April 22, 2023 · 1 min · 97 words · Me

## Matrix Decomposition

Matrix decomposition example Let N be the number of possible simulated paths, T be the number of time periods, and P be the number of parameters to estimate. For now, let’s suppose that N = 4, T=2 and P=2. Below is an example with T-by-N matrix. The rows indicates different time periods, and the columns indicate different simulated paths $$n \in \{1,2,3,4\}$$. For example, $$A = \begin{bmatrix} a_{11}\theta + b_{11}\rho & a_{12}\theta + b_{12}\rho & a_{13}\theta + b_{13}\rho & a_{14}\theta + b_{14}\rho \newline \beta(a_{21}\theta + b_{21}\rho) & \beta(a_{22}\theta + b_{22}\rho) & \beta(a_{23}\theta + b_{23}\rho) & \beta(a_{24}\theta + b_{24}\rho) \end{bmatrix} \newline$$ When n =1, $$\begin{bmatrix} 1 & \beta \end{bmatrix} \begin{bmatrix} a_{11} & b_{11} \newline a_{21} & b_{21} \end{bmatrix} \begin{bmatrix} \theta \newline \rho \end{bmatrix}$$ When n =2, $$\begin{bmatrix} 1 & \beta \end{bmatrix} \begin{bmatrix} a_{12} & b_{12} \newline a_{22} & b_{22} \end{bmatrix} \begin{bmatrix} \theta \newline \rho \end{bmatrix}$$ When n =3, $$\begin{bmatrix} 1 & \beta \end{bmatrix} \begin{bmatrix} a_{13} & b_{13} \newline a_{23} & b_{23} \end{bmatrix} \begin{bmatrix} \theta \newline \rho \end{bmatrix}$$ When n =4, $$\begin{bmatrix} 1 & \beta \end{bmatrix} \begin{bmatrix} a_{14} & b_{14} \newline a_{24} & b_{24} \end{bmatrix} \begin{bmatrix} \theta \newline \rho \end{bmatrix}$$...

April 21, 2023 · 3 min · 447 words · Me

## Quantitative Economics with Julia

for loop in, ∈, = Below three for loops return the same output. Note that in, ∈, = can be used interchangeably to indicate that i loops over the following array, 1:2:10 which indicates that the array ranges from 1 to 10 with an increment of 2. for i in 1:2:10 println(i) end for i ∈ 1:2:10 println(i) end for i = 1:2:10 println(i) end Output: 1 3 5 7 9 eachindex I also introduce in this post eachindex, which returns the index of a given vector....

April 20, 2023 · 1 min · 120 words · Me

## DataFrames.jl (3) and Pipe

Selecting and transforming columns When selecting variables of a data frame, we do add : to indicate that it’s a variable name. Thus for example, if we want to select column with variable x, we use :x inside select(). First let’s construct some 500 by 3 dimensional data frame called df that contains three columns each of which has name of A, B, and C. using DataFrames df = DataFrame( A=1:2:1000, B= repeat(1:10, inner=50), C= 1:500) Each of below codes produces 500 by 1 dataframe, a data frame that only contains column A....

April 19, 2023 · 2 min · 313 words · Me

## SymPy.jl

SymPy.jl When functions are linear in parameters, we can decompose a matrix of polynomials into a matrix of coefficients and a matrix of variables. To achieve this, we can use the SymPy package. First we need to ensure that Julia recognizes variables and treats them as symbols. using SymPy x, y = symbols("x, y") Then we can simply invoke thecoeff() method to extract coefficients from the polynomials. p = x + 0....

April 16, 2023 · 1 min · 200 words · Me

## DataFrames.jl (2)

Taking a Subset We can subset a dataframe using index. For example we can subset specific columns and rows by following codes. # column subset (subset df to only include column A and C) df[:, [:A, :C]] # row subset (subset df to only include 1st, 3rd, and 5th rows) df[[1,3,5], :] We could also use some selectors such as Not, Between, Colsand All. Following code removes columns whose names match r"x"....

April 12, 2023 · 1 min · 152 words · Me

## DataFrames.jl (1)

Create dataframe To create a dataframe, simply use DataFrame function after loding DataFrames.jl. Following code produces a dataframe composed of three variables, A, B, and C, each of which has 500 rows. Each row of column A increments by 2 starting from integer 1. Column B repeats 50 times of each integer starting from 1. Coumn C lists integers from 1 to 500. using DataFrames df = DataFrame(A=1:2:1000, B= repeat(1:10, inner=50), C= 1:500) first, last The first and last functions act as head and tail function in R, which allow us to view the first or the last couple of rows of the dataset....

April 11, 2023 · 2 min · 236 words · Me

## Basics of Julia

Basics In Julia, the name of the variables can be very flexible; we can use Unicode as a variable name. You can also use Unicode math symbols as variable names. To do so, type a backslash followed by the Latex Symbol; then press tab to autocomplete. For example, to type the alpha symbol, simply type “\alpha” followed by tab. # Assigning values to different types to variables x = 1 안녕하세요 = 2 y = "안녕하세요" # We can use Unicode math symbols by backslash Latex symbol followed by tab....

March 30, 2023 · 4 min · 651 words · Me