Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
robertopucp
GitHub Repository: robertopucp/1eco35_2022_2
Path: blob/main/Trabajo_grupal/WG1/Grupo_8_jl.ipynb
2714 views
Kernel: Julia 1.8.0
#Ejercicio 5 using Random using Distributions using DataFrames Random.seed!(756) x1 = rand(500) # uniform distribution x2 = rand(500) # uniform distribution x3 = rand(500) # uniform distribution x4 = rand(500) # uniform distribution e = randn(500) # normal dsitribution mean = 0 y sd = 1 Y = ones(500) + 0.8.*x1 + 1.2.*x2 + 0.5.*x3 + 1.5.*x4 + e X = hcat(ones(500),x1,x2,x3,x4) function ols(M::Matrix, Y, standar = true, Pvalue = true, instrumento = nothing, index = nothing) if standar && Pvalue && isnothing(instrumento) && isnothing(index) beta = inv(transpose(X) * X) * (transpose(X) * Y) y_est = X * beta n = X.shape[0] k = X.shape[1] - 1 nk = n - k sigma = sum(list( map( lambda x: x**2 , Y - y_est) )) / nk Var = sigma*inv(transpose(X) * X) sd = np.sqrt( np.diag(Var) ) t_est = np.absolute(beta/sd) test = 3.5 dist = TDist(4) # 4 grados de libertad Pvalue = 2*(1 - cdf(dist, test)) df = pd.DataFrame( {"OLS": beta , "standar_error" : sd , "Pvalue" : pvalue} ) elseif !isnothing(index) && !isnothing(instrumento) beta = inv(transpose(X) * X) * (transpose(X) * Y) index = index - 1 Z = X Z[:,index] = z beta_x = inv(transpose(Z) * Z) * (transpose(Z) * X[:,index]) x_est = Z * beta_x X[:,index] = x_est beta_iv= inv(transpose(X) * X) * (transpose(X) * Y) df = pd.DataFrame( {"OLS": beta , "OLS_IV" : beta_iv}) end ols(X,Y) ols(X,Y,instrumento = z, index = 2)
syntax: missing comma or ) in argument list Stacktrace: [1] top-level scope @ In[68]:27 [2] eval @ .\boot.jl:368 [inlined] [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String) @ Base .\loading.jl:1428