antiquekrot.blogg.se

Stata collapse
Stata collapse








stata collapse
  1. #STATA COLLAPSE INSTALL#
  2. #STATA COLLAPSE CODE#

When asking for help with code, always show example data. In this case you can also tell Stata to keep list of variables This. To drop entire variables, simply type drop variable name If you have a giant data set and only want to keep one or two variables, it is a lot faster to do the opposite command.

stata collapse

It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data. If you used a criterion that does not apply to any of your variables, Stata simply drops 0 cases. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. dataex- will save you time it is easier and quicker than typing out tables. Either way, run -help dataex- to read the simple instructions for using it.

#STATA COLLAPSE INSTALL#

If not, run -ssc install dataex- to get it. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. In the future, show data examples when you want help with code, and use the -dataex- command to do so. But if you had a Stata internal format monthly variable for the year and month of birth, then you would just -collapse- with that one variable in the -by()- option. How you do that will depend on whether your year and month variables are numeric or string, so, again, without example data, specific advice cannot be given. (I wrote tag () in 1999, and I am not aware of this as a misunderstanding.) There is a related but so to speak distinct problem where tag () comes in useful, which is counting distinct values (often called unique values). For most purposes, you will be better off having a single variable that combines the year and month of birth into a single Stata internal format monthly date variable. collapse (count) countfoo (mean) meanfoo (sd) sdfoo, by (locID year) I doubt that any Statalist posts state otherwise. That said, I also suggest you change your data organization.

#STATA COLLAPSE CODE#

Since you left that to the reader's imagination, you get back code tailored to imaginary data. Had you posted example data, custom code, tested, could be provided.

stata collapse

Collapse (count) n_births = obs_no, by(birth_year birth_month)Obviously you need to tailor that to the actual variable names in your data set.










Stata collapse