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
CADF testHello everyone, Country:18 Year:17 I'm using STATA for two weeks. I want to achieve the CADF unit…
StanStandard error for wald test …
Looking at Heteroskedastickty with Random EffectsHello, I was wondering how i can graphically inspect my residual distribution and see whether a hete…
I need to explain these commands in panel regressionPlease I am new in STATA I find these commands in a paper please can you explain for me before we r…
Suppress legend on histogramHello all, I would like to create a histogram of a 4-level categorical variable (hh_comp) that descr…
Subscribe to:
Post Comments (Atom)
0 Response to using export excel in combination with conditional statement
Post a Comment