0

I'm wondering how to replace missing values in Stata for certain rows only (as noted above).

I have a long column with 842 cells. The first 160 should be 1, and the rest should be 0. However, I have missing values scattered throughout 1-842. How can I replace the missing values in 1:160 with 1, and the missing values in 161:842 with 0?

3
  • Welcome to SO! Which rows? How will you identify them? What have you tried? What do you want to replace them with? Commented Apr 27, 2020 at 4:22
  • Hi Stuart! I Have a long column with 842 cells. The first 160 should be 1, and the rest should be 0. However, I have missing values scattered throughout 1-842. How can I replace the missing values in 1:160 with 1, and the missing values in 161:842 with 0? Commented Apr 27, 2020 at 4:30
  • To Stata programmers, rows are observations and columns are variables. Stern conventions here to focus on the technical question and answer are friendlier than they may seem: everyone benefits long-term from avoidance of personal comments. Commented Apr 27, 2020 at 7:00

1 Answer 1

2
replace myvar = cond(_n <= 160, 1, 0) if missing(myvar)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.