{smcl} {bf:Mata course: Functions} {hline} {title:Example} {cmd}real matrix id(real scalar n) {c -(} real scalar i real matrix res res = J(n, n, 0) for (i=1; i<=n; i++) {c -(} res[i,i] = 1 {c )-} return(res) {c )-}{txt} {title:Syntax} {p 4 8 2} 1. They are used in Mata programs {p 4 8 2} 2. They follow the classic definition {p 12 16 2} f({it:a},{it:b},{it:c},...) returns a value based on {it:a}, {it:b}, {it:c}, ... {p 8 8 2} or {p_end} {p 12 16 2} f({it:a},{it:b},{it:c},...) returns multiple values by modifying its arguments {p 8 8 2} or {p_end} {p 12 16 2} f({it:a},{it:b},{it:c},...) does something but returns nothing {p 4 8 2} 3. The words function, subroutine, and program are used interchangeably; all mean the same thing {title:Flavors of functions} {p 4 8 2} 1. Built-in {p_end} {p 12 16 2} They are part of Mata itself, and are written in C {p 4 8 2} 2. Library {p_end} {p 12 16 2} They are part of Mata, and are written in Mata {p 4 8 2} 3. User written {p_end} {p 12 16 2} All other, including the functions (programs, subroutines) you write {p 4 4 2} Sometimes the word built-in is used to refer to (2). {hline} {bf:{view talk.smcl:Top}}