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
Group the market value of listed companies according to a specific dateI have the Daily market value data of listed companies,like: stock_code date ME 1 01oct1978 1000000 …
Saving tabulated dummy variable scalars (i.variable)Hello, I'm trying to run an estimation for my honours thesis detailed in this paper (open-source ve…
separating digits from the numerical variable.Hi All!, I am facing a problem with nsso data while merging four files such as household, demograph…
How to write loops that fill a matrix successivelyHello, I've got a question regarding the writing of loops: What I would like to do is to write a lo…
how to obtain the correct AIC / BIC values after a model using [pw=...]Hi everyone, In general, I use -estat ic- or -fitstata- to obtain the bic & aic values after th…
Subscribe to:
Post Comments (Atom)
0 Response to using export excel in combination with conditional statement
Post a Comment