>Notepad++ tips 3

>Soft tabs are enabled as follows:

Settings > Preferences > Language Menu/Tab Settings > Tab size = 4 + enable “Replace by space”

Posted in Notepad++ | Leave a comment

>Notepad++ tips 2

>If auto-indentation is activated and you want to reprint code in for example a \( \LaTeX \) document with the verbatim environment, you should convert tabs into spaces, otherwise \( \LaTeX \) will not recognize the spaces as such and indented code will not properly be reprinted.

In order to convert tabs to spaces, just do the following:

TextFX -> TextFX Edit -> Leading space to tabs or tabs to spaces

Posted in Notepad++ | Leave a comment

>R code for OLS

>Just to show the mathematics involved in computing the OLS coefficients on a simulated data set (which is a good approach to really learning econometrics):

set.seed(1234)
n <- 1000
x1 <- rnorm(n)
x2 <- runif(n)
X <- cbind(1, x1, x2)
k <- ncol(X)
beta <- c(2, 4, 6)
y <- X %*% beta + rnorm(n)
XtX <- crossprod(X)
Xty <- crossprod(X, y)
b <- solve(XtX, Xty)
yhat <- X %*% b
resid <- y - yhat
s2 <- sum(resid^2)/(n - k)
sigma.hat <- s2 * solve(XtX)
se <- sqrt(diag(sigma.hat))
res <- cbind(b, se)
colnames(res) <- c("b", "se")
rownames(res) <- c("const.", "x1", "x2")
res
summary(lm(y ~ X - 1))

Note how the code makes use of efficient matrix algebra on computing the OLS coefficients:

for

t(X) %*% X
crossprod(X, y)

for

t(X) %*% y

and especially,

solve(XtX, Xty)

which is a numerically stable method for solving a system of linear equations, instead of the standard textbook OLS computation \( \beta_{\text{OLS}} = (X’ X)^{-1} X’ y \), translated to R code as

solve(t(X) %*% X) %*% t(X) %*% y
Posted in Econometrics, Numerical methods, Programming, R | Leave a comment

>Optimized ATLAS BLAS speed gains in R

>After reading this, I decided to give it a go myself and replaced the default Rblas.dll with the the one linked against the ATLAS library and, indeed, speed gains in matrix computations are significant.

I used the C2D version linked against ATLAS 3.9.11, available here.  Here are the results of the same experiment:

require(Matrix)
set.seed(123)
X <- Matrix(rnorm(1e6), 1000)
print(system.time(for(i in 1:25) X%*%X))
print(system.time(for(i in 1:25) solve(X)))
print(system.time(for(i in 1:10) svd(X)))


Default Rblas.dll

> print(system.time(for(i in 1:25) X%*%X))
   user  system elapsed
   24.71    0.25    24.96
> print(system.time(for(i in 1:25) solve(X)))
   user  system elapsed
   17.66    0.03    17.72
> print(system.time(for(i in 1:10) svd(X)))
   user  system elapsed
  50.46    0.68   51.15 

ATLAS optimized Rblas.dll

> print(system.time(for(i in 1:25) X%*%X))
   user  system elapsed
   4.80    0.11    4.92
> print(system.time(for(i in 1:25) solve(X)))
   user  system elapsed
   4.82    0.20    5.03
> print(system.time(for(i in 1:10) svd(X)))
   user  system elapsed
  21.18    0.64   21.83

So, like I said, significant speed gains for such a simple trick as replacing the Rblas.dll.  This is the Pareto principle in practice: minimum effort for maximum result!

Posted in Numerical methods, R | Leave a comment

Notepad++ tips 1

Notepad++ is a very versatile editor; I use it for programming in R and C/C++ and also as a LaTeX editor.  For programming languages the following features come in handy, i.e. (1) auto-close and (2) auto-completion.

Continue reading

Posted in Notepad++, Programming | Leave a comment

Configuring Code::Blocks with GSL

Youtube has a video on how to configure Code::Blocks for use with the GNU Scientific Library (GSL), see below.  There’s no sound, the platform is Linux (and Spanish apparently), but good enough to follow the changes/modifications on screen.

Continue reading

Posted in C/C++, Numerical methods | Leave a comment

What to expect

Like the title says, this blog is a vehicle for things I’m interested in from both a professional (economics, numerical methods and programming) and personal point of view (literature, music and other stuff). Continue reading

Posted in Uncategorized | Leave a comment