Metrics
Metrics

Reputation: 15458

What is the equivalent of Stata "." in R

I have a Stata command which generates the new variable y with value .

gen y=. 

I want to know whether following is the equivalent command in R"

y<-NA

Upvotes: 2

Views: 691

Answers (2)

Fr.
Fr.

Reputation: 2885

As the other answer indicates, missing data in an object that can be compared between Stata and R, such as a data.frame, will be coded as NA. NULL is another possibility. Here's an empty matrix:

> x = matrix(); x
     [,1]
[1,]   NA

It's also possible to have zero-length objects, like an empty string:

> x <- ""; x
[1] ""

To go back to the useful part of the answer, NA and is.na are the bits that you want to memorize.

Upvotes: 1

agstudy
agstudy

Reputation: 121568

Using this

In Stata the basic missing value for numeric variables is represented by a dot .

In R the missing values are represented by NA.

Starting with version 8 there are 26 additional missing-value codes denoted by .a to .z. These values are represented internally as very large numbers, so valid_numbers< . < .a < ... < .z.

R haven't such representation of missing data. all missings data are represneted by NA.

In Stata To check for missing you need to write var >= .

In R, we use is.na to check for missing data.

Upvotes: 6

Related Questions