R to Stata and Stata to R

 1. NA

In R, NA is considered as missing value. But in Stata, NA is considered as a string value. So having a NA in your variable will change the type of your variable. 

One solution is to use the "write.csv" function in R. 

#R code

vdem<-readr::read_csv("vdem0724.csv")

#na="."-->therefore, if you read this file in Stata, it will be seemed as .

write.csv(vdem,"vdem0724.csv", na=".",row.names = TRUE, fileEncoding = "UTF-8")

*Stata code
import delimited ".\vdem0724.csv", varnames(1) 


Comments

Popular Posts