{smcl} {* *! version 1.2 14Dec2021 of this help file for version 1.7 of -repshow-}{...} {cmd:help repshow} {hline} {title:Title} {hi:repshow} - Replace observations and show what has been changed {title:Syntax} {p 8 17 2} {cmd:repshow} {it:oldvar} {cmd:=}{it:exp} {ifin} [{cmd:,} {opt nop:romote} {opth id(varname)} {opth l:istvars(varlist)} {opt v:erbose} *] {synoptset 20 tabbed}{...} {synopthdr} {synoptline} {syntab:Main} {synopt:{opt nop:romote}}prevent promotion of a variable type{p_end} {synopt:{opth id(varname)}}variable to identify listed observations{p_end} {synopt:{opth l:istvars(varlist)}}additional variable(s) listed for changed observations{p_end} {synopt:{opt v:erbose}}provide additional details on the operation{p_end} {synopt:{opt *}}options passed through to the {help list} command{p_end} {synoptline} {p2colreset}{...} {p 4 6 2} {cmd:by} is not allowed; see {manhelp by D}.{p_end} {p 4 6 2} {cmd:weight}s are not allowed; see {help weight}. {title:Description} {pstd} {cmd:repshow} shows the changes made by the {help replace} command. Basic syntax is exactly like {help replace}. Options {opth id(varname)} and {opth l:istvars(varlist)} display the values of other variables for the same observations that are changed by the {help replace} command. These options are for information only. {cmd:repshow} makes use of the {opt mean} and {opt N} options of the {help list} command to display these summary statistics for the changed observations. In addition any options which typically apply to the {help list} commmand can be added. {title:Options} {phang} {opt nopromote} prevents {opt replace} from promoting the {help data types:variable type} to accommodate the change. See help for {help replace} for details. {phang} {opt id} selects a variable for the first column of the output so the user can identify the changed observations. {phang} {opt listvars} selects additional variables to be displayed to give the user further information about the changed observations. {phang} {opt verbose} adds some explanatory text to the output, but does not change the results. {title:Remarks} {pstd} Version 1.7 of {cmd:repshow} accepts string variables. See the {help repshow##strexample:example} below. {pstd} The {cmd:repshow} command lists the old and new versions of the replaced variable for every replaced observation. Thus if the user intends to change the values of hundreds of observations, Stata's {help replace} command may be more convenient. {title:Example} {pstd} Here is an example using Stata's expanded version of their automobile data. {com}. webuse fullauto, clear {txt}(Automobile models) {pstd} A cross-tabulation shows that the 1977 repair record variable is missing for 8 cars., Thus, an analysis using the variable {cmd:rep77} must drop or impute 8 observations. {com}. tab rep77 rep78, mi {txt}Repair {c |} record {c |} Repair record 1978 1977 {c |} Poor Fair Average Good Excellent . {c |} Total {hline 11}{c +}{hline 66}{c +}{hline 10} Poor {c |}{res} 1 0 2 0 0 0 {txt}{c |}{res} 3 {txt} Fair {c |}{res} 1 7 2 0 1 0 {txt}{c |}{res} 11 {txt} Average {c |}{res} 0 1 19 6 1 0 {txt}{c |}{res} 27 {txt} Good {c |}{res} 0 0 5 11 4 0 {txt}{c |}{res} 20 {txt} Excellent {c |}{res} 0 0 0 0 5 0 {txt}{c |}{res} 5 {txt} . {c |}{res} 0 0 2 1 0 5 {txt}{c |}{res} 8 {txt}{hline 11}{c +}{hline 66}{c +}{hline 10} Total {c |}{res} 2 8 30 18 11 5 {txt}{c |}{res} 74{txt} {pstd} For three of the cars missing a repair record in 1977, a record is available for 1978. Suppose one decides to "impute" (or guess) the values of these three missing values by replacing them with the values for the same cars for 1978. The advantage of using {cmd:repshow} instead of {help replace}, is that a record of the operation will be recorded in the log file. {pstd} Here is the output produced by {cmd:repshow}. The option {cmd:verbose}, elicits the expository legend or caption above the listed results. {com}. repshow rep77 = rep78 if missing(rep77), id(model) list(make foreign ) verbose {txt}(3 real changes made) Comparison of -{res}rep77{txt}- before and after execution of -replace- The column -{res}model{txt}- identifies the observations The column -{res}Old vrsn{txt}- gives the values of -{res}rep77{txt}- before the replace. The column -{res}New vrsn{txt}- gives the values of -{res}rep77{txt}- after the replace. The column(s) {res}make foreign{txt} are for information only. {c TLC}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 9}{c -}{hline 10}{c TRC} {c |} {res} model Old vrsn New vrsn make foreign {txt}{c |} {c LT}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 9}{c -}{hline 10}{c RT} 32. {c |} {res} Fiesta . Good Ford Domestic {txt}{c |} 44. {c |} {res}Monarch . Average Merc. Domestic {txt}{c |} 56. {c |} {res}Horizon . Average Plym. Domestic {txt}{c |} {c LT}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 9}{c -}{hline 10}{c RT} Mean {c |} {res} . 3.333333 13.6667 0 {txt}{c |} N {c |} {res} 0 3 3 3 {txt}{c |} {c BLC}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 9}{c -}{hline 10}{c BRC} {pstd} The following cross-tabulation shows the changes in the {cmd:rep77} values of the three cars. {com}. tab rep77 rep78, mi {txt}Repair {c |} record {c |} Repair record 1978 1977 {c |} Poor Fair Average Good Excellent . {c |} Total {hline 11}{c +}{hline 66}{c +}{hline 10} Poor {c |}{res} 1 0 2 0 0 0 {txt}{c |}{res} 3 {txt} Fair {c |}{res} 1 7 2 0 1 0 {txt}{c |}{res} 11 {txt} Average {c |}{res} 0 1 21 6 1 0 {txt}{c |}{res} 29 {txt} Good {c |}{res} 0 0 5 12 4 0 {txt}{c |}{res} 21 {txt} Excellent {c |}{res} 0 0 0 0 5 0 {txt}{c |}{res} 5 {txt} . {c |}{res} 0 0 0 0 0 5 {txt}{c |}{res} 5 {txt}{hline 11}{c +}{hline 66}{c +}{hline 10} Total {c |}{res} 2 8 30 18 11 5 {txt}{c |}{res} 74 {txt} {marker strexample} {pstd} Starting with version 1.7, {cmd:repshow} works the same on string variables as on numeric variables. Since the {cmd:fullauto} data contains no string variables, first make string versions of the two categorical variables {cmd:make} and {cmd:model}. {com}. decode make, gen(make_str) . decode model, gen(model_str){txt} {pstd} Suppose we know that Maserati surreptitiously purchased the Fiesta assembly line from Ford in 1977. To replace the make for Fiesta, we can proceed as follows. {com}. repshow make_str = "Maserati" if model_str=="Fiesta", id(model_str) list(make model) {txt}variable {bf}{res}make_str{sf}{txt} was {bf}{res}str7{sf}{txt} now {bf}{res}str8{sf} {txt}(1 real change made) Comparison of -{res}make_str {txt}- before and after execution of -replace- {c TLC}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 8}{c TRC} {c |} {res}model_~r Old vrsn New vrsn make model {txt}{c |} {c LT}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 8}{c RT} 32. {c |} {res} Fiesta Ford Maserati Ford Fiesta {txt}{c |} {c BLC}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 8}{c BRC} ************************************************************* {title:Stored results} {pstd} In contrast to the {help replace} command, which leaves no stored results in Stata's {help return:return space}, {cmd:repshow} returns the name of the {it:oldvar} variable and the number of differences between the original version of {it:oldvar} and its new version after {cmd:repshow} is executed, {cmd:r(ndif)}. macros: r(repvar) : "sy" r(ndif) : "7" {title:Author} {p 4 8 20} {browse "http://www.cgdev.org/content/experts/detail/10007/":Mead Over}, Center for Global Development, Washington, DC 20036 USA. Email: {browse "mailto:mover@cgdev.org":MOver@CGDev.Org} if you observe any problems. {p 4 8 20} Version 1.7 is indebted to Stata's Chris Chen for advice on using {help syntax}'s anything(equalok) option. {* *! version 1.1.1 24feb2012}{...} {* *! version 1.1.2 10Dec2021 Corrected typo in "Remarks". Changed the example to one that can be executed by the user.}{...} {* *! version 1.2 14Dec2021 Documents -repshow-'s new ability to work with string variables.}{...}