Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
robertopucp
GitHub Repository: robertopucp/1eco35_2022_2
Path: blob/main/Grupo 1/Grupo 1.ipynb
2714 views
Kernel: Julia 1.6.7
# **Miembros del grupo** # 20163197, Enrique Alfonso Pazos # 20191894, Ilenia Ttito # 20151595, Rodrigo Ramos # 20193469, Luis Eguzquiza # 20163377, Jean Niño de Guzmán
# Instalamos paquetes e importamos librerías import Pkg Pkg.add("LinearAlgebra") Pkg.add("Random") Pkg.add("Distributions") Pkg.add("Statistics") Pkg.add("DataFrames")
Resolving package versions... No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Project.toml` No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Manifest.toml` Precompiling project... IJulia 1 dependency successfully precompiled in 9 seconds (55 already precompiled) 1 dependency precompiled but a different version is currently loaded. Restart julia to access the new version Resolving package versions... No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Project.toml` No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Manifest.toml` Precompiling project... IJulia 1 dependency successfully precompiled in 8 seconds (55 already precompiled) 1 dependency precompiled but a different version is currently loaded. Restart julia to access the new version Resolving package versions... No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Project.toml` No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Manifest.toml` Precompiling project... IJulia 1 dependency successfully precompiled in 8 seconds (55 already precompiled) 1 dependency precompiled but a different version is currently loaded. Restart julia to access the new version Resolving package versions... No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Project.toml` No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Manifest.toml` Precompiling project... IJulia 1 dependency successfully precompiled in 8 seconds (55 already precompiled) 1 dependency precompiled but a different version is currently loaded. Restart julia to access the new version Resolving package versions... No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Project.toml` No Changes to `C:\Users\Jean M\.julia\environments\v1.6\Manifest.toml` Precompiling project... IJulia 1 dependency successfully precompiled in 8 seconds (55 already precompiled) 1 dependency precompiled but a different version is currently loaded. Restart julia to access the new version
using LinearAlgebra, Random, Distributions, Statistics,DataFrames Random.seed!(175) x1 = rand(500) x2 = rand(500) x3 = rand(500) x4 = rand(500) e = randn(500) X = hcat(ones(500),x1,x2,x3,x4) Y = ones(500) + 0.8.*x1 + 1.2.*x2 + 0.5.*x3 + 1.5.*x4 + e #PGD function ols(M::Matrix, Y::Matrix, standar::Bool = True, Pvalue::Bool = True , instrumento = nothing, index = nothing) if standar && Pvalue && isnothing(instrumento) && isnothing(instrumento) beta = inv(transpose(X) * X) * (transpose(X) * Y) y_est = X * beta n = size(M,1) k = size(M,2) - 1 nk = n - k sigma = sum( map((x) -> x^2, (Y-y_est) )) / nk Var = sigma*inv(transpose(X) * X) dVar=diag(Var) sd = dVar.^0.5 t_est = abs.(beta/sd) test = 3.5 dist = TDist(nk) # n-k grados de libertad Pvalue = 2*(1 - cdf(dist, test)) df = DataFrame(Betas = beta, ErrorStand = sd, P_value=pvalue ) elseif (not instrumento is None) and (not index is None) : beta = np.linalg.inv(X.T @ X) @ ((X.T) @ Y ) index = index - 1 Z = X Z[:,index] = z beta_x = np.linalg.inv(Z.T @ Z) @ ((Z.T) @ X[:,index] ) x_est = Z @ beta_x X[:,index] = x_est beta_iv = np.linalg.inv(X.T @ X) @ ((X.T) @ Y ) df = pd.DataFrame( {"OLS": beta , "OLS_IV" : beta_iv}) return df print(ols(M,Y))
syntax: missing comma or ) in argument list Stacktrace: [1] top-level scope @ In[19]:38 [2] eval @ .\boot.jl:360 [inlined] [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String) @ Base .\loading.jl:1116
a=[-1,-4,-9] abs.(a)
3-element Vector{Int64}: 1 4 9