Skip to content

Keep stata



 

Keep stata. 安装程序文件 Timestamps:0:00 - Intro y abrir base de datos0:38 - Keep y drop (quedarse con casos)2:16 - Drop (eliminar ciertos casos)6:46 - Keep y drop por rango de casos Nov 16, 2022 · Any text-delimited file (*. Regards. In this video, we look at how to use keep/dr Oct 26, 2019 · Hello, I am trying to select a couple of cases in a dataset - and perform a set of operations/changes on those cases. Nov 16, 2022 · This command creates a new variable newid that is 1 for the first observation for each individual and missing otherwise. This is not peculiar to Stata: it is mathematics and you will run into the same thing with any statistical package (although a different statistical package might omit different variables Mar 10, 2015 · In that case, you would want to go farther and eliminate any of the retained observations where there is only a single postal code among them. Nov 16, 2022 · Case 4: Dropping duplicates based on all the variables. For this I use a number of foreach loops in combination with the collapse and reshape commands. Each type is discussed below. Those observations not selected disappear. input long householdnumber byte household_number_member. Code: reg cashflow assets if year==1991 & industry==1. So let us say I want to delete the variables that show prices of cars to be greater than 12,000. clear. I know I could simply save all graphs, but especially when I am cleaning my data set I Re: st: how to keep maximum value. Jul 23, 2018 · 3. In such a case, the following rules are used to determine the variable type in Stata of the imported column. Code: predict res if year==1991 & industry==1, xb. Newson, R. Nov 16, 2022 · Title. Nov 8, 2014 · 1. Plus sign means “match one or more” of the preceding expression. 2002. 2020. foreach i of num 1/2 {. To install: ssc install dataex. local keep make price sales. Stata can store strings up to 2-billion characters long and can store strings containing binary information, including binary 0 (\0). Always keep a log. Stata Journal 4: 484–485. Re: st: Keeping Open Multiple Graph Windows? Date. _n is the Stata way of referring to the observation number; in a 10-observation dataset, _n takes on the values 1, 2, , 10. It is tedious and error-prone. 2010. Jan 24, 2018 · You can keep or drop a variable in its entirety, but you cannot do so only in some observations, as the syntax attempts to do. We use a clear command at the start of this example so that we can reload the afewcarslab dataset: . 5 in [U] for an explanation on how _n and _N work in connection with the -by varlist:- construct. keep works the same way as drop, except that you specify the variables or observations to be kept rather than the variables or observations to be deleted. Moving on, we can also use the drop command and the keep command to drop certain values based on conditions. See help macrolists for details. 2013. collapse with if works this way: Those observations selected by the if condition are collapse d, typically (but not necessarily) into a new dataset with fewer observations. 3 Dec 6, 2017 · If Stata is eliminating variables due to colinearity, then there is simply no mathematical possibility of estimating the effects of all of those variables. Jul 13, 2019 · For instance, in the data above, I want to run a regression like. local tokeep : list vars & keep. . drop eliminates variables or observations from the data in memory. ( like varible1==1 and variable2==1) please some one help me with necessary command. If you are not sure that import delimited will do what you are looking for, see[D] import and [U] 22 Entering and importing data. This command works fine if I only put in 10 or 20 zips. marginscontplot: Plotting the marginal effects of continuous predictors. There are several duplicates in terms of "objectid" and "year". And you can tell it's dong that if you have 3000000 observations. Jun 8, 2023 · bysort race: outreg2 using sumstat. Jul 8, 2021 · 2. My code looks like this: Code: clear. For numeric values, 254 elements are allowed and for string values, only 9. Then, for each distinct id, the new variable firstdate is calculated as the first value, which is the minimum. They will not insure against other effects of the commands you type (effects on matrices, mata, locals, program definitions, etc). Stata基础:数据删除和保留 (drop+keep) stata删除缺失值以及保留连续年份数据,删除空缺值后,即可拿到连续固定年份完整有效面板数据。. keep() is used to pare the merged dataset to a given set of observations when you do not care if there are other observations in the merged dataset. i am facing a problem with "keep" command. (meaning all variables named " rep " followed by something), or it can be a range of variables. Drop/Keep. harvard. ) Preview lets you see how the data will look in Stata even before you import them, even from data on the Internet. The equivalent for last date calculations, . There is one record per kid. In SPSS, I can use SELECT IF to temporarily restrict operations to cases fiting that criteria. It's incorrect to say that this command is unusual, let alone unique, in that respect. Actually, you can combine those into a single command. Be especially careful when selecting observations within groups. 10000028 1. There are two possible approaches, and which you use depends on whether there are other variables in your data set which you wish to retain. Changing mpg from 12 to 10, however, does not really affect the sort order. I have enormous data with repeating information. or it can be all variables starting with a certain prefix. Subject. Once the limit has been reached, Stata/MP falls back to writing preserved datasets to disk. This is a handy way to make sure that your ordering involves multiple Remarks and examples stata. version 14. keep keep tells Stata to drop all variables except those specified explicitly or through the use of an if or in expression. if year >= 2008 & month >= 7. From these duplicates, I would like to keep the one with the highest value in "count". Everything works fine however, if I have numerous graphs in my do. If you don't know all the variables you want to drop, to keep only the blocks with varx and vary : keep varx* varz*. turn. turn foreign#i. The default setting for set max preservemem is 1g, meaning 1 gigabyte. Oct 20, 2011 · inlist () may also be used for numeric values. #2. If you -set emptycells drop- and later want to turn that off, the command is -set emptycells keep-. The aim is to group observations, those with the lowest value all being assigned a grade 1, the next lowest being all assigned 2 and so forth. 2. . You may see another User Account Control dialog box asking whether Stata can make changes to your computer. Oct 12, 2022 · keep and drop of coefficients from coefplot. Code: Jan 6, 2019 · Using the Stata sort and bysort command will allow us to fix this problem. What follows is relevant only if you are using Stata/SE or Stata/MP. com When working with binary strings, one can find the first or last location of the binary 0 using strpos(s, char(0)) or strrpos(s, char Sep 20, 2016 · I do this using the below code: Code: gen one=1. A variable is what looks like a column. For more info, type help dataex. Here is a file containing information about the kids in three families. Thanks in advance! In order to merge two datasets, we need a common variable (or a set of variables) called a ‘key’ variable present in both the master and using file. e. If the y2's are constant within y1's, then Stata will move along and do the -collapse-. To unpack this command line, Stata sorts on id first and then within id on date. When _n is combined with by, however, _n is the observation number within by-group, in this case Nov 16, 2022 · and, as previously mentioned, this is _n in Stata terms when referring to observations. , 1 is first), age wt and sex are the child’s age, weight and sex. Warning: drop and keep are not reversible. variable rather than a 1/0 variable. Stata has other commands for importing data. Stata tip 114: Expand paired dates to pairs of dates. Tue, 23 Sep 2008 22:37:42 +0100. In Stata, this condition becomes y[_n] > record[_n - 1] But y[_n] can just be written y, as Stata by default always works on the current observation number (or, more precisely, all of them in sequence). An example may help: 10 10 5 0 is taken to be the normalized CMYK value 5 5 0 5. Nov 16, 2022 · To save memory, especially with a large file, we might want to drop spells of missing values at the beginning of each panel, at the end, or both. Royston, P. keep if !mod(end,1) Nick On Thu, Sep 1, 2011 at 11:10 AM, Nick Cox <[email protected]> wrote: > -int(end)- is not a true or false test of whether its argument is > integer. keep () within cells () - does not appear to work with coefficient names that contain spaces. This prevents estpost tabulate from trying to construct coefficient names from the labels. sort OK random. The reason is that, in the file structure, there . It seems there is some interaction between these two options that throws things off. ) 3. Of course, to use the by command we must first sort our data on the by variable. Picking up where case 3 left off, this is no different from case 2. This is normal for the first time you launch Stata. Nov 16, 2022 · would be better. May specify delimiter, including multiple-character delimiters. The maximum line length is defined as 16 more than the maximum macro length, which is currently 645,200 characters. drop _all (see[D] drop). Follow. In this case, it is year. keep() differs from assert() because it selects observations from the merged dataset rather than enforcing requirements. The order of Boolean operations in Stata, as in most programming languages, is that & takes precedence over |. If so, the code for that is: Code: replace EBreceived = . Nov 4, 2016 · Given that your two number series don't have any obvious pattern, I don't think there is any alternative to listing them. It does not modify your data set. inlist() with string arguments is fiddly in particular if that is part of the solution. Similarly, export delimited writes Stata’s data to a text file. 1 Arithmetic operators The arithmetic operators in Stata are + (addition), - (subtraction), * (multiplication), / (division), ^ (raise to a power), and the prefix - (negation). sysuse auto . use country22. Stata may be dumb, but it is Sep 21, 2023 · The inclusion of singletons affects the estimation's degrees of freedom, which, in turn, impacts the calculation of the standard errors. Starting a log is just a matter of adding a command at the top of your do-file that tells Stata to log, as well as where you want the log to be saved: Apr 1, 2021 · input str40 make "AMC Concord" "Buick Regal" "Buick Skylark" "Model T" end tempfile makes save `makes' sysuse auto. Also see [D] compress — Compress data in memory [D] corr2data — Create dataset with specified correlation structure Mar 8, 2016 · Posts: 28244. Code: sort ticker fyear analys anndats. Stata Guide: Drop/Keep. A workaround is to use the elabels option with estpost tabulate. Stata Journal 2: 86–102. Stata uses, for lack of a better term, normalized CMYK values. generate insample = OK & (_N - _n) < 100. smcl" for smcl , ". I was unable to do this using the community-contributed command coefplot. In principle you could type out one or more commands defining a keep condition, but that is a poor solution as. ds. dta, clear merge m:1 make using `makes' keep if _merge==3 list make price And this is the output of the interesting part of the code. display "`tokeep'". 论文实证从国泰安CSMAR数据库直接下载下来的数据并不能直接用于stata数据分析,数据整理时需要怎么做?. B. In STATA, I think I can temporarily use KEEP Nov 12, 2020 · Forums for Discussing Stata; General; You are not logged in. by group: generate n2 = _N. local vars `r(varlist)'. csv, *. Share. edu>: > How do you keep open multiple graph windows in Jul 31, 2016 · The element-specific keep () option - i. drop if price> 12000. edu. hellow all. You can change that in Stata/SE and Stata/MP. As I say, I think with these particular definitions of A, B, and C, this isn't a problem. 通过上述范例可以看出,使用 Stata 自带的 keep 和 drop 命令可以快捷地删除变量或观察值,但在命令写法上较为繁琐。. by id (date), sort: gen lastdate = date[_N] will not be what you want: any missing values will end up as the Remarks and examples stata. A series where I help you learn how to use Stata. I just recently switched from using Stata 15 to Stata 16. Instead it uses the values and stores the labels in e We will illustrate this using an example showing how you can collapse data across kids to make family level data. This conversion can be done using the string() function with an option for the format. 2004. After a regression in Stata, I am trying to plot only the coefficients of the interaction terms. It means, I want to generate this following result: Explore how to keep and drop observations and variables in Stata using the drop and keep commands. Here is sample data: * Example generated by -dataex-. Title stata. Nov 25, 2020 · Welcome to my classroom!This video is part of my Stata series. That would be: Code: by orgnr (postal_code), sort: drop if postal_code[1] == postal_code[_N] See section 11. But it never hurts to use the more robust coding with parentheses. Perhaps what you really mean is that you would like to replace values of EBCreceived with missing values if year >= 2008 & month >= 7. The bysort command has the following syntax: bysort varlist1 (varlist2): stata_cmd. The same commands are used for dropping / keeping variables or cases. Products. contract and keep also work in this way Jan 21, 2015 · see the slides on the notebook interface. drop if dup>0. Learn ways to temporarily store and recall data with the preserve and restore commands. I tried to do this using the below code but it did change the order of the data, so Stata was correct. rtf" for rft , ". We can use the keep command to keep just these five variables. file, it only shows me the latest graph in the Stata graph editor but gets rid of the former ones. 1) No other variables need to be retained. list length turn. score group id nt n1 n2. Stata/SE and Stata/BE are typically used on computers with less memory and as such always preserve datasets on disk. html" for html -merge- does not allow "if" (note that Stata does not put "if" after the comma, as you have it, anyway) however, you could always split the file into two, one for epr==2 and one for epr!=2, do your merge and then -append- the files 2estimates store— Store and restore estimation results Menu Statistics > Postestimation Syntax estimates store name, nocopy estimates restore name estimates query Another is . The following code corresponds to my using dataset: * Example generated by -dataex-. I would like to keep variables from the same day but in a specific time range e. dta (called the using dataset), matching on one or more key variables. 12 Oct 2022, 05:33. drop var17-var103 var314 var317. We can merge the data using the menu option provided in the following sequence: Data > Combine datasets > Merge two datasets. Code: sysuse auto, clear. Rather it rounds towards zero, and the result is an integer: > if that result is non-zero if it is treated as true. So what you want is. com Remarks are presented under the following headings: Description of the model Fitting unconstrained models Fitting constrained models mlogit fits maximum likelihood models with discrete dependent (left-hand-side) variables when the dependent variable takes on more than two outcomes and the outcomes have no natural Using _n and _N in conjunction with the by command can produce some very useful results. After saving the operations, I can remove the restrictions to work on the full dataset. list. statalist@hsphsun2. Here are the core operators that Stata’s regular expression parser supports: Asterisk means “match zero or more” of the preceding expression. The logical way to do this in stata is to write a command that looks like this: keep if zip=="12345" | zip=="12456" | zip=="00234" | zip==. Preserve/restore can minimize damage to the dataset, but only if you use them. I am using the coefplot command using the following example of data. Nov 16, 2022 · or. May 18, 2011 · I'd say this question is posed the wrong way round for best understanding. 将不同单个表格的 Mar 29, 2022 · tsline TasaGralG, yline(. Here is a reproducible example and my attempted solutions: sysuse auto, clear. g. generate insample = (_N - _n) < 100. If stata cmd stores results, only the results from the last group on which stata cmd executes will be stored. At the end of the code, only the last graph is shown. Whether you have one fixed effects variable or multiple variables does not change this, although the issue may be exacerbated with many fixed effects variables due to the lower initial degrees of freedom. all the variables on 09jan2013 in the range of 19:00:00 to 19:30:00. Description. For this module, we will focus on the variables make, rep78, foreign, mpg, and price. Jun 24, 2018 · The key is using a macro list function to select variables that appear in both the list of variables to keep and the list of variables in the dataset. 3436966), graph save "C:\Users\bruno\OneDrive\Documents\Trabajo\Robin\graph_TasaGralG", replace. I'm wondering how do I tell Stata to keep each Oct 17, 2018 · Is it possible to keep only selected variables in esttab, as I want the output only for i. will delete the variables listed after "drop" from your data set. scml files to refer back to, and kept your data safe, manual editing of output is easier at the early stages. š"HÛlÑ Û \iVKX$eRòÚùõ=3CŠ jtÙÍ6 Ã+Š ž9—ï Officially correct syntax is, use if _n <100 using mydata or, better yet, use in 1/99 using mydata (This latter syntax is much more efficient. In this case, I would like to have only one row per ID, in the end, I would like to only have seven To. If there is only 1 value of Surveyyear in a group, I'll keep all of the observations in that group. If amt is set to 0b Oct 17, 2021 · 10001200 2. i got a data which contains 5 to 6 variables, now i want to keep those data which fill up the two conditions at a time. Birth is the order of birth (i. sort group score. 5 %ÐÔÅØ 21 0 obj /Length 2739 /Filter /FlateDecode >> stream xÚÝZ[ ÛÆ ~ß_Á·J€5žû% j4. However, I want to keep a selection of cells that have less than 20 observations so I want to tell Stata to drop those with less than 20 observations except the ones I specify. For example: gen asean4 = 1 if inlist (countrycode, 360, 458, 608, 764) The difference between using numeric and string values is in the number of allowable elements in the list (number of countries in our example). cond() works like this: . This module shows the use of if with common Stata commands. May 8, 2017 · Keeping only the first observation. Automatic delimiter detection for commas, tabs, semicolons, colons, and pipes. assert() is used to Apr 18, 2021 · merge the datasets and keep the intersection defined by _merge being 3. Apr 18, 2021 · The maximum allowed length is 645,216 characters, which is calculated on the basis of set maxvar. 1. J. input byte(rev149 rev729) float comLevPvt byte(ms_afm_18_1 rev190 rev130_2) float sex_before_mar. Aug 4, 2015 · 04 Aug 2015, 00:39. The command would look something like this. age and i. Login or Register by clicking 'Login or Register' at the top-right of this page. doc, replace sum(log) keep (age union grade tenure ln_wage) NOTE: You need to specify either keeping statistics (eqkeep) and droping variables (drop) or viceversa. S. In general however, if you type clear all, Stata will clear all, and this is irreversible. Below we show an example; the variable 'x' is a numeric value, and not a string. csv" for csv and scsv , ". txt" for fixed and tab , ". end. Stata tip 13: generate and replace use the current sort order. drop if response >= . label drop _all (see[D] label) clear mata removes Mata functions and objects from memory and is equivalent to Mar 22, 2021 · Keeping graphs in graph editor. Quick start Load comma-delimited mydata. Note that, in contrast to SPSS, you cannot drop or keep variables while Dropping values using keep or drop function. preserved datasets. merge can perform match merges (one-to-one, one-to-many, many-to-one, and many-to-many), which are often called joins by database Nov 16, 2022 · Not only is the syntax wrong, but it reflects a misunderstanding of the two ways that -keep- can be used and how Stata data sets are organized. Oct 6, 2014 · The easiest generic way to keep the last of a group is as follows. This isn't ranking in most senses that I have seen discussed, but Stata's egen, rank() does get you part of the way. 13. I also tried to group the industry and year first and then regression as follows. keep if mod(end, 1) == 0 or . If you have your . txt files. ) But in any case, my experience has been that it always reads through the whole file. Also see [D] contract — Make dataset of frequencies and percentages [D] expandcl — Duplicate clustered observations [D] fillin — Rectangularize dataset Nov 16, 2022 · Many Stata users also wish to convert numeric data to strings and keep the leading zeros, which is good for U. Launch Stata. Author. If filename is specified without suffix, a default suffix is added depending on the specified document format (". 我们可以使用外部命令 savesome 来提高效率 (该命令是 Stata 官方命令 save 的扩展版):. The dash operator means “match a range of Hence, I try to use the following code to keep the last forecast per analyst firm year, but it does not delete 6 out of the 7 observations for analys 79092. smoke. As far as Stata is concerned, any change to the variables on which the data are sorted means that the data are no longer sorted, even if the change actually leaves the order unchanged. keep make rep78 foreign mpg price Apr 2, 2018 · The keep() and assert() options are operating in a way I really can't get my head around, and clearly not in the way that documentation for merge describes. FIrst, let's be clear about terminology. Using "keep" instead of drop would delete all variables not listed. If you want two or more distinct random subsamples, you can extend this approach. Dec 7, 2019 · 3. which both restores the original data set and keeps the preserved copy alive. Click on Yes to continue. Stata orders the data according to varlist1 and varlist2, but the stata_cmd only acts upon the values in varlist1. list rep*. The generalisation is. Code: * Example generated by -dataex-. Technical note: Mixed data types Because Excel’s data type is cell based, import excel may encounter a column of cells with mixed data types. Stata Journal 13: 217–219. %PDF-1. Speaking Stata: Concatenating values over observations. May specify multiple delimiters. -set empty cells- affects the way Stata sets up the matrices it uses to do regression estimations. You must enter something for all the fields in the Initialize License dialog before you can continue. txt, etc. References Cox, N. egen cellsize=count(one), by (variableofinterest) drop if cellsize<20. 08 Mar 2016, 15:02. (Also, if you exit Stata and re-start it, any previous -set emptycells drop- is forgotten. Let’s use the auto data file. You can browse but not post. The * means “match zero or more” of the preceding expression. Understand that whenever Stata wants a varlist it can be a list of variables, such as. Opening the Word file from the directory will give us the following table. But if there are exceptions, Stata will tell you that the "assertion is false" and give you a count of the number of exceptions, and then halt Jul 15, 2019 · Can I use the same command you provided in #8 for the following situation: I want to select a sample in a balanced panel data in a way I keep the representativeness of the variable "region" and also keep the panel balanced with information of the person id for each year of the panel. drop if dup>1. There is nothing wrong with sorting on categorical variables by themselves— sort patid and sort group —just do not assume that the order within the grouping variable is unique. Stata has four different classes of operators: arithmetic, string, relational, and logical. Apr 14, 2020 · I am quite new to stata so I would really appreciate your help. Nov 19, 2018 · 1. If you want to drop all duplicate observations, including the first occurrence, type. There would be about 700 "or" conditions. Also, missing values may occur in the middle of each panel, that is, in observations not contiguous with blocks at the beginning or at the end. by ticker fyear analys anndats, sort: keep if _n == _N. Question mark means “match either zero or one” of the preceding expression. csv with the variable names on the first row Jul 28, 2020 · 一步到位保存数据子集: `savesome` 命令. use afewcarslab The compiled table is displayed in the Stata results window or, optionally, written to a text file specified by using filename. That simply means that at least one of the CMY values is normalized to 0 for all CMYK colors, with the K (black) value “absorbing” all parts of CM and Y where they are all positive. For more information on Statalist, see the FAQ. You can read more Mar 11, 2024 · - If you want to retain only selected variables from the "using" file, you need to use keepusing command and tell Stata which variables you want to keep. Probably the most typographically simple way to accomplish this is: Code: gen Group = "garden" if inlist(id, 1, 5, 7, 12, 13, 15) replace Group = "control" if inlist(id, 2, 3, 6, 8, 9, 14) But (not to be condescending, but to be realistic), if you are totally new to Stata, it can take more time to automate something than it does to just edit manually. For each group of caseID that has more than 1 value of Surveyyear, I want to keep observations that have the maximum value of Surveyyear. thamks to all. edited Nov 8, 2014 at 16:10. merge joins corresponding observations from the dataset currently in memory (called the master dataset) with those from filename. I have a small challenge. Jan 1, 2017 · Code: by y1 (y2), sort: assert y2[1] == y2[_N] Put that line into your code just before the -collapse- command. I have date-time variables which I converted from string and they are in this form: 09jan2013 13:43:18 (together in one cell). //(31,606 observations deleted) * count # of analysts. by ticker fyear , sort: gen analyno=_N. Keeping a log means you can go back and look at what you did without having to do it again. For example, if you want two groups of equal size. log or . *split dataset by setting (1=community; 2=health care) preserve. bysort <variables defining groups> (<variable defining order first last>): keep if _n == _N. Paul Lin, StataCorp. Speaking Stata: How to move step by: step. Social Security numbers, times, dates, etc. In other words, be careful. By adding the name () option to your graph: *** sysuse auto scatter price mpg, name (first) histogram price, name (second) *** HTH, Eva 2008/9/23 <jasonm@ucla. If sampling is only from within observations that are OK, as above, then. com clear — Clear memory DescriptionQuick startSyntaxRemarks and examplesAlso see Description clear, by itself, removes data and value labels from memory and is equivalent to typing. In Stata, an observation is what looks like a row when you view the data in the Browser. Improve this answer. Again, this is a general rule of thumb on Stata. Nov 16, 2022 · Setting up the license. Apr 24, 2019 · If you notice a mistake like a wrong -drop- command, then you just issue -restore- and a new -preserve- command to undo the changes. by group: generate n1 = _n. If you want to drop all duplicate observations but keep the first occurrence, type. 1/0 variables are generally more useful. reg price foreign i. assert() is used to I have a big dataset that I’m trying to split in multiple much smaller datasets. For example, if you want to merge mydata1 and mydata2, and want to merge variables x4 and x5 only from mydata2 to mydata1, use the following codes: From Ana Gabriela Guerrero Serdan < [email protected] > To [email protected] Subject Re: st: comparing dates: keep if dates<d(DDMMYYYY) Date Fri, 23 Jan 2009 16:42:48 -0800 (PST) keep() differs from assert() because it selects observations from the merged dataset rather than enforcing requirements. The problem is, Stata doesn't allow this many "OR" conditions in that statement. Greetings. This will prevent Stata from and-ing the last term of A with the first term of B rather than and-ing all of A with all of B. Dec 22, 2016 · In Stata, I have 3 variables: "objectid", "year", and "count". Stata Journal 13: 510–527. Shortcuts to refer multiple variables. relationship between Stata datetimes and Excel datetimes. For a concrete example I assume panel data with identifier id and time variable time: bysort id (time): keep if _n == _N. Just like drop, keep can be used with varlist or with qualifiers but not with both at once. answered Nov 6, 2014 at 16:59. Any arithmetic operation on a missing Cox, N. 10000031 1. do and . As the commands are executed line by line, the graphs open and then immediately are closed as the next one is produced. You can’t specify eqkeep() and keep() at the same time. I would like to keep only the first row per ID. and then predict residuals using. Code: gen G = 1 if a == 1 & (b == 1 | b == 2) Comments: This generates a 1/. Code: restore, preserve. by repeats the stata cmd for each group defined by varlist. qv up fg va tv cs nk yq ei to