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:41] – [Exemples] 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("MASS")
   install.packages("readODS")   install.packages("readODS")
Line 65: Line 67:
 #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 87: Line 90:
  
 #summary statistics table       #summary statistics table      
-stargazer(as.data.frame(db1), type="text", summary=TRUE)+  stargazer(as.data.frame(db1), type="text", summary=TRUE)
  
 # tabulate # tabulate
-table ("Age"=db1$age,"Sexe"= db1$sexe) +  table ("Age"=db1$age,"Sexe"= db1$sexe) 
-db1 %>% tab(age, sexe) +  db1 %>% tab(age, sexe) 
-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.1748871690.txt.gz · Last modified: by glebelg