As the doctor gone rogue

February 28, 2011

Making R “BEEP”

Filed under: R, STATA — hypotheses @ 5:00 pm

I started noticing the beep after an interactive command finish in STATA (I think this is only a Mac specific feature). In STATA, you get a “beep” when the command finish running and you are working in other programs. Some commands take some times to finish, and it is nice to have that feature.

In R, if you want it to beep, some options are “alarm() function”, which is pretty much “cat(“\a”)” . You can make R tweet, too (see http://stackoverflow.com/questions/3365657/is-there-a-way-to-make-r-beep-play-a-sound-at-the-end-of-a-script)

I think I’d rather go with something simple like cat(“\a”).
But, there are lots of comments about “\a” not working unless you have a speaker turned on. So, make sure your computer has a speaker, though.

If you are running a script in Linux, you can use a command to send mail at the end of your R script — something like

system(‘mail hypotheses@me.com -s “Job finished” < logfile’)

[I haven’t tested it out though]… Do you have any other ideas?

Advertisements

February 16, 2011

Working with date on Stata

Filed under: data management, STATA — Tags: , , — hypotheses @ 3:25 pm

Recently, I received a data coding date, for example, as 8/8/2011 for Aug 8, 2011. When importing this file into STATA, STATA automatically treated this as string. To be able to manipulate “date” easily, I converted it to numeric variable

gen int ndate = date(date, “MDY”)

Then for STATA to display this variable properly in a human readable format

format ndate %td

I, then, I have a question about the mid-visit date, which can now be easily calculated as

mean ndate if visit==2

This gave me number like 18302

Till now, the only way to find out what day this is for me is

display day(18342) month(18342) year(18342)

I think there might be an easier way to split out the DMY format, but I don’t know how yet.

For further information about working in date in STATA, I refer you to the resource on UCLA website, and help files in STATA.

Blog at WordPress.com.