Now on to the actual looping and appending. It retains the values that are in A, B or both (without creating duplicates). The vertical bar | is Stata’s OR operator. In this instance, the manipulation is the join of two lists. However, dir has been replaced by list to indicate the new local is the manipulation of some list. This command is very similar to the ones we’ve been using before. > datafile_1.dtadatafile_2.dtadatafile_3.dtadatafile_4.dtadatafile_5.dtadatafile_10.dtadatafile_11.dtadatafile_12.dtadatafile_13.dtadatafile_14.dtadatafile_15.dta local allbutthebeer_datafiles_all : list allbutthebeer_datafiles1 | allbutthebeer_datafiles2 It’s generally not very convenient to work with two macro’s (a local is a macro), so we’d like to combine them. dta this time, as the extension is technically part of the filename. Now we have two lists, allbutthebeer_datafiles1 which has the single digit files and allbutthebeer_datafiles2 which has the double digit ones. > datafile_10.dtadatafile_11.dtadatafile_12.dtadatafile_13.dtadatafile_14.dtadatafile_15.dta > datafile_1.dtadatafile_2.dtadatafile_3.dtadatafile_4.dtadatafile_5.dta Instead, we’ll need the question mark ? wildcard, which substitutes for one and only one character. What if we wanted all the datafiles except the beer ones? We can’t just use “datafile*” as pattern, because that would still collect the beer files. If you don’t care, just scroll down and replace “allbutthebeer_datafiles_all” by “beer_datafiles”. Before we get to the appending, I’m going to make our life a bit more difficult, just to show you how much you can do with locals in Stata. We had five beer datafiles and the list contains all five. > datafile_beer_1.dtadatafile_beer_2.dtadatafile_beer_3.dtadatafile_beer_4.dtadatafile_beer_5.dta As it is a local list, double quotes are not necessary (and indeed will produce an error). Remember to enclose the local name within apostrophes (`…’). The display command shows the contents of the local. Finding the right pattern can be tricky sometimes. This particular pattern takes files that contain the word beer and optionally have something in front or behind it. The asterisk * is a wildcard that could be any number of characters.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |