Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // read in some file here
  2. // suppose outcome is called weight
  3. // and vars are height age
  4. // to run reg weight height age:
  5. mata:
  6. X = buildX("height age")
  7. Y = buildY("weight")
  8. results = runreg(X,Y)
  9.  
  10. function buildY(string scalar outcomes){
  11. Y = st_data(., tokens(outcomes))
  12. return(Y)
  13. }
  14. function buildX(string scalar vars){
  15. X = st_data(., tokens(vars))
  16. return(X)
  17. }
  18. function runreg(matrix X, colvector y)
  19. {
  20. n = rows(X)
  21.  
  22. X = X,J(n,1,1)
  23.  
  24. XpX = quadcross(X, X)
  25.  
  26. XpXi = invsym(XpX)
  27.  
  28. b = XpXi*quadcross(X, y)
  29.  
  30. return(b[1,1])
  31.  
  32. }
  33.  
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement