How to Save Predicted (or manually generated) Values into the Original Data?

Hi, and welcome!

The haven package provides a facility to write Stata dta files from data frames and tibbles.

If you have data in the form of a data frame or tibble and model output with a vector of predictors for each observation (which means you must exclude all NA cases) you should be able to add the predictors as a column with cbind or, preferably, dplyr::mutate and then haven::write_dta(your_df, path, n) where n is Stata version 8-15.

If you get stuck along the way, please post a new topic with a reproducible example, called a reprex so peeps here can weigh in on specifics.

1 Like