User Tools

Site Tools


econometricsr

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
econometricsr [2025/06/02 13:21] glebelgeconometricsr [2025/06/04 11:44] (current) glebelg
Line 1: Line 1:
-====Start a script ====+=====Start a script =====
      
   library(stargazer)   library(stargazer)
Line 13: Line 13:
 data from Rdata data from Rdata
      
-====Summary Stats====+=====Summary Stats=====
  
   stargazer(dataset, type = "text", title= "Summary Statistics", digits = 2, out="output.csv")   stargazer(dataset, type = "text", title= "Summary Statistics", digits = 2, out="output.csv")
Line 22: Line 22:
      
          
-====Regressions====+=====Regressions=====
  
 linear linear
   reg1 <- lm(depvar ~ var1 + var2 + var3, data=dataset)   reg1 <- lm(depvar ~ var1 + var2 + var3, data=dataset)
 +use rlm for robust regressions  
 +  
      
 probit probit
Line 34: Line 36:
      
      
-====Exemples====+=====Exemples====
 +  install.packages("MASS"
 +  install.packages("readODS"
 +  install.packages("tidyverse"
 +  install.packages("devtools"
 +  devtools::install_github("gvelasq/tidytab"
 + 
  
 #load libraries #load libraries
-#import ods+  #import ods
   library(readODS)   library(readODS)
-#import xls/xlsx  +  #import xls/xlsx  
   library(readxl)   library(readxl)
-#robustify fonction +  #robust lm 
-  library(bucky+  library(MASS
-#for tables+  #for tables
   library(stargazer)   library(stargazer)
   library(tidytab)   library(tidytab)
-# for data manipulation+  # for data manipulation
   library(tidyverse)   library(tidyverse)
      
Line 56: Line 65:
   db2<-read_excel("dbtest.xlsx")   db2<-read_excel("dbtest.xlsx")
  
-# generate variables in dataset+#generate variables in dataset
   db1$niveauscore <- db1$niveau * db1$score   db1$niveauscore <- db1$niveau * db1$score
-    #option2 - si beaucoup d'opérations!+     
 +#option2 - si beaucoup d'opérations!
     attach(db2)     attach(db2)
     db2$niveauscore <- niveau * score     db2$niveauscore <- niveau * score
Line 66: Line 76:
     db1$niveauminscore <- niveau - score     db1$niveauminscore <- niveau - score
     detach(db1)     detach(db1)
 +    
 +    
          
 # OLS regressions # OLS regressions
          
-    model1 <- robustify(lm(score ~ age, data=db1),type = c("HC1")+    model1 <- rlm(score ~ age, data=db1) 
-    model2 <- robustify(lm(score ~ niveau, data=db1),type = c("HC1")+    model2 <- rlm(score ~ niveau, data=db1) 
-    model3 <- robustify(lm(score ~ age + niveau, data=db1),type = c("HC1"))+    model3 <- rlm(score ~ age + niveau, data=db1)
          
     stargazer(model1, model2, model3, type="text",     stargazer(model1, model2, model3, type="text",
Line 85: Line 97:
   db1 %>% tab1(age, sexe)   db1 %>% tab1(age, sexe)
   db1 %>% ftab( sexe, age)   db1 %>% ftab( sexe, age)
 +
 +=====Import/Export=====
 +import excel
 +  library(readxl)
 +  db <- read_excel("db.xlsx")
 +  View(db)
 +import stata
 +  library(haven)
 +  db <- read_dta("db.dta")
 +  View(db)
 +  
 +export excel
 +  install.packages("xlsx")
 +  library(xlsx)
 +  write.xlsx(db, file = "db.xlsx")
 +
 +=====Data Manipulation=====
 +
 +====drop publicates====
 +  newdata <- distinct(dataset,varname, .keep_all = TRUE)
  
econometricsr.1748870492.txt.gz · Last modified: by glebelg