Dear data cleaners
I made a small program to check whether there is a constant called cons in the data set, and if not, to make it and set its value equal to 1. I use it when I don't know what a program is doing. The system variable _cons doesn't seem to work in all applications (e.g. in collapse). I would like to throw it on SSC so that if I share my syntax, people can also download it and proceed. I actually have a couple of such little ado's and perhaps I should group them.
Please vent your opinion if this little ado would be a good practice, or whether it is useless or redundant.
Thanks
Sem
cap program drop mkcons
program define mkcons
capture sum cons
if _rc == 0 {
if (r(min) != r(max)) | (r(mean) !=1) {
replace cons = 1
di as result "Cons is not constant or not equal to 1"
}
else {
di as result "Cons = 1 already exists"
}
}
if _rc != 0 {
gene byte cons = 1
di as result "Cons = 1 has been made"
}
end
mkcons
Related Posts with -mkcons- .ado to make a constant
Using a nested foreach loop to merge and then append multiple files from multiple folders into one dataset.Essentially, I have a few thousand text files, for which I have a nested foreach loop to import them…
P-ValueCan some one explain to me what this piece of code is doing? I know it is related to creating a P-Va…
Difference in Difference (DiD) with xtabond and xtdpdsysHello everyone, I am trying to work out how to complete a DiD analysis with Difference GMM and Syst…
Test for trend using mi postestimationHi all, I'm attempting to test for a trend in age category and other ordinal variables on my depend…
multilevel models with non-nested dataHello, I'd like information about multilevel models with non-nested data. . Could someone indicate a…
Subscribe to:
Post Comments (Atom)
0 Response to -mkcons- .ado to make a constant
Post a Comment