Parenting with Stata
Sunday, 30 August 2009
My daughter will be eight days old by the time I'm done writing this. She's on food intake and diaper watch, so among the things we brought home from the hospital was this pink sheet where we were supposed to record full diapers and feeding patterns. Of course we then filled it out, and when my wife tried to download a fresh one from the hospital website she could not find any such thing.
No big loss that, because I don't approve of pen-and-paper data entry anyway. Instead, I propose baby_watch.do, below. It time-stamps feeding and excretion events and records them to baby_watch.txt:
clear
set more off
set type double
pause on
// GENERAL INSTRUCTIONS
/*
How this works:
Update the locals breast, wet, and dirty with bytes 0 or 1
as needed -- e.g., 1 0 0 means baby was breast-fed, and
diaper was clean; or 0 1 0 means a wet diaper was changed.
Update the local named bottle with ounces of formula drunk
(if you don't need to supplement, count your blessings and
leave it at zero).
Notes:
The clock() time is in seconds since 00:00:00 on Jan 1, 1960.
That's a very large number. It's easier to just have a string
that can be converted into Stata format date if needed, sorts
in chronological order, and is legible. The mask that I thought
worked best on all counts was %tcCCYYNNDD_HH:MM.
*/
// EVENTS, FILE PATHS, FILE NAMES
// --- update these as needed, every time
local bottle 2.5
local breast 0
local wet 1
local dirty 0
// --- change these with what works for you
local whereis "//oldirons/public/baby/"
local myfile "baby_watch.txt"
// --- no need for any changes below this line
// PROGRAM DEFINITIONS
// ### time-stamp the latest event
capture program drop latestEvent
program latestEvent
args bottle breast wet dirty
drop _all
set obs 1
local when clock("`c(current_date)' `c(current_time)'", "DMY hms")
local when: di %tcCCYYNNDD_HH:MM `when'
gen when ="`when'"
gen bottle =`bottle'
gen byte breast=`breast'
gen byte wet =`wet'
gen byte dirty =`dirty'
end
// ### update the baby status file
capture program drop updateFile
program updateFile
args whereis myfile bottle breast wet dirty
capture confirm file "`whereis'`myfile'"
if _rc!=0 {
latestEvent `bottle' `breast' `wet' `dirty'
}
else {
insheet using "`whereis'`myfile'", clear
preserve
tempfile latest
latestEvent `bottle' `breast' `wet' `dirty'
save "`latest'", replace
restore
append using "`latest'"
}
sort when
outsheet using "`whereis'`myfile'", replace
end
// PROGRAM CALLS
updateFile `whereis' `myfile' `bottle' `breast' `wet' `dirty'
There you have it. If you or somebody you know decide to take baby_watch.do for a spin, please let me know how it goes.
No. 1 — August 30th, 2009 at 2:28 pm
Thanks Gabi, great post. I've recently been thinking a lot about Stata as a data entry tool and your post is an example of how to accomplish this. However, data entry via a do-file can be tedious & error-prone when:
1) the number/type of entries is large and
2) the person entering the data has little experience with Stata do-files.
I am running into this problem where I give a data entry task to some research assistants who are not familiar with Stata do-files. I just end up creating a data entry screen in Excel (using the "Validation" tool) or by creating an online survey tool that is really just a controlled data entry screen. Then I import the data from these files, clean them up, and run the analysis.
An additional challenge comes in when I am working on a client's remote secure server where they allow access to Stata or R, but not to MS programs or the internet. I wish there were a data entry screen, much like the one available in MS Access, so that the novice user could easily input data directly into a Stata dataset. I have found an old article and reference to the Stata user programs -winshow- -winset- and -diablo- which appear to work together to create a data entry screen using the stata dialog boxes -db- environment. However, it appears that these have not been updated in quite a while & when I try to run these on auto.dta, I get the error "control not allowed r(101)". -Trace- reveals that the error comes after the program issues the command -- window control clear-. Admittedly, I haven't yet put much time in trying to resolve this error or get into the source adofiles.
DM63 in this PDF ( http://www.stata.com/products/stb/journals/stb46.pdf ) has a good explanation about the utility & capabilities of -winshow- and -winset-, but again I cannot get the examples to work. My suspicion is that it has something to do with features in Stata's -window programming- and -db- commands that have changed since it's creation & therefore broken -winshow- and -winset-.
Anyways, I thought that this program, if someone could get it to work, would be ideal for repetitive data entry much like you've described, especially for novice user, & that this is a feature that is sorely missing from Stata. I've considered posting a question on Statalist when I've had a chance to dig deeper into the problems and made better attempts to come up with a working solution.
No. 2 — August 31st, 2009 at 4:36 pm
At the Stata conference in DC in July, Sergiy Radyakin gave a great presentation on how he tweaked Stata graphics to make graphs show patterns for true black-and-white printing (right now, Stata graphs only do solid colors, which in monochrome appear as different shades of gray, which works OK with the better printers we have these days). Sergiy accomplished this with the use of a few hidden commands, and he wondered aloud why they were hidden. I quote from memory, but Bill Gould gave him two reasons I remember. One is that though StataCorp uses these commands internally, it deems them of too little use to the typical customer to be worth documenting and maintaining. The other is that undocumented commands can be dropped or changed as needed.
My guess is that the broken examples you mention made some clever use of such hidden commands that now work differently, or are gone for good.
I expect that Numerics with Stata will open up all sorts of opportunities for third-party developers to build and sell stuff like data-entry GUI solutions. I agree that using do-files the way I did is unsatisfactory for field use.