Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // read in some file here
- // suppose outcome is called weight
- // and vars are height age
- // to run reg weight height age:
- mata:
- X = buildX("height age")
- Y = buildY("weight")
- results = runreg(X,Y)
- function buildY(string scalar outcomes){
- Y = st_data(., tokens(outcomes))
- return(Y)
- }
- function buildX(string scalar vars){
- X = st_data(., tokens(vars))
- return(X)
- }
- function runreg(matrix X, colvector y)
- {
- n = rows(X)
- X = X,J(n,1,1)
- XpX = quadcross(X, X)
- XpXi = invsym(XpX)
- b = XpXi*quadcross(X, y)
- return(b[1,1])
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement