

subinstr(s, old, new, cnt) returns s with the rst cnt occurrences of old changed to new. if `variab'`variab'`hcut' & `variab'~=.ĭi " `var' & " %7.2f r(mean) " & " %7.2f r(sd) " & " %7.2f r(p25) " & " %7.2f r(p50) " &" %7.2f r(p75) " & " %7.0fc r(N) "ĭi " `var' & " %7.2f r(mu_1) " & " %7.2f r(sd_1) " & " %7.0fc r(N_1) " & " /// Title subinstr() Substitute text DescriptionSyntaxRemarks and examplesConformability DiagnosticsAlso see Description subinstr(s, old, new) returns s with all occurrences of old changed to new. etc.Įgen `variab'`lcut'=pctile(`variab'), p(`lcut') by(type_id US)Įgen `variab'`hcut'=pctile(`variab'), p(`hcut') by(type_id US) 2subinstr() Substitute text Diagnostics subinstr(s, old, new, cnt) and subinword(s, old, new, cnt) treat cnt < 0 as if cnt 0 was specied the original.

Here is one solution using the macro extended function -subinstr- (-help extendedfcn-). subinstr(s, old, new, cnt), subinword(s, old, new, cnt): s: r 1 c 1 old: r 2 c 2 new: r 3 c 3 cnt: r 4 c 4 (optional) s, old, new, cnt r-conformable result: max(r 1,r 2,r 3,r 4) max(c 1,c 2,c 3,c 4) 1. * it is done by type_id US, could be by firm_id year. For example, if I have the following data, I want to generate new variables countSS, countSM, and countSG that contains the number of occurrences of SS, SM, or SG in variable awards. * list of variables to winsorize/check for extreme values: If you do not issue the clear command and there is already data in memory that has changed since last being saved, Stata. * dropping extreme values (could be adjusted for winsorizing as well) Mlabels("US Nondurable" "US Durable" "UK Nondurable" "UK Durable") /// Labels("Firm-years" "Firm deviations p-value" "Link test p-value" )) eqlabels(none) replace /// Here is one solution using the macro extended function -subinstr- (-help. For example, if I have the following data, I want to generate new variables countSS, countSM, and countSG that contains the number of occurrences of 'SS', 'SM', or 'SG' in variable awards.
Subinstr stata how to#
local names : subinstr local names 'pig' '', word. Somebody asked how to count the number of occurrences of a string within a string.

Estout gc`i'USnondur gc`i'USdur gc`i'UKnondur gc`i'UKdur /// In Stata, words are or could be separated by spaces (other than being bound by double quotes) in the case of Stata variable names, distinct variable names are always distinct words.
