Dear all,
Would you be able to advise me on the following?
I have written several checks to flag data inconsistencies (e.g. are there duplicate subject ids in my data set?)
If such a check finds any inconsistencies (at least one observation), I want to export these cases to Excel, so I can share these observations with the colleague that is responsible for collecting and cleaning the data.
Stata will stop running my code if the inconsistency check finds no observations ("Too many or no variables specified"). However, I have about 20 of these inconsistency checks and it is time consuming to tell Stata to continue running the rest of the code every time it does not find any observations in an inconsistency check.
So what I would like is for the code below to run only if there is at least one observation to export and if there are no observations to continue running my dofile instead of stopping and telling me "Too many or no variables specified")
I have tried:
(A):
export excel using "$data/data_inconsistency_check1.xls", replace firstrow(var) if _n > 0
--> Result: Unfortunately export excel does not accept if statements
(B):
foreach i in subjectid {
export excel using "$data/data_consistency_check1.xls", replace firstrow(var)
}
--> Result: this gives me the same "Too many or no variables specified" message when there are no observations to export, and if there would be more than 1 observation, the export would be performed multiple times, so this would not be a suitable solution to be honest.
Thank you kindly for your ideas and suggestions,
Best wishes,
Moniek
Related Posts with using export excel in combination with conditional statement
How would you export ANOVA tablesforeach var in Subclass { anova ATF4Targetgenes `var' export ?????????? } Hello everyone, I have c…
Base category not displayedFellow stata users, I am having trouble getting state to display the base category of the interactio…
Questions about pseudo-strata/psu in complex survey designHi: This is not a stata related question, so please forgive me if this is not allowed. I am dealin…
Criteria to apply xtpcseHello everyone. I have a dataset with N = 178 and T =14 . Is it right to go for panel corrected stan…
convergence not achieved in GMM ModelDear Statailist I run the GMM regression of my variables in STATA and I have error that w that "co…
Subscribe to:
Post Comments (Atom)
0 Response to using export excel in combination with conditional statement
Post a Comment