Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Dialog programming: (I)what lists can be passed (II)How to put quotes


From   "David Elliott" <dcelliott@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Dialog programming: (I)what lists can be passed (II)How to put quotes
Date   Fri, 3 Nov 2006 18:11:31 -0400

I am making my first foray into dialog programming and it is a steep
climb up the learning curve.

(I)
I basically want a dialog to do the following:

1) if no dataset is open, open a dataset or, if one is open, use it or
open a different one.  I know how to do this with the FILE control and
filter() option

2) subsequently, I want to populate two variable lists to be used in
COMBOBOX dropdownlists.  They should consist of (a) a list filtered to
include only numeric variables and (b) a list of all variables (I
don't want to use the VARLIST control unless I absolutely have to)

I have already figured out that, since Stata must load the file first
to populate the lists, I have to have an intermediate step to open the
file.  Also, since the dialog must wait for that action, I have made
it a SYNCHRONOUS_ONLY dialog.

I'd like to populate my lists with:

PROGRAM LOAD_VAR /*Load Measure and Grouper varlists*/
BEGIN
foreach var of varlist * {
	local type : type `var'
	global allvar $allvar `var'
	if inlist("`type'","byte","int","long","float","double") {
		global measlist $measlist `var'
		}
	}
END

or, alternatively, something like

PROGRAM LOAD_VAR /*Load Measure and Grouper varlists*/
BEGIN
put "quietly ds, not(type string)"
stata
global measlist `r(varlist)' /* would contain all numeric variables */
put "quietly ds"
stata
global allvar `r(varlist)'
END

I can see that my lists have been created by issuing a post dialog
-mac dir-. Unfortunately, I can't tell if this sort of construct is
allowed for COMBOBOX controls although you appear to be able to pass
global strings to an EDIT control.  So am I trying to micturate to
windward here?  I can see other situations where one might want to
pass lists to a combobox, for example have contents(variable labels)
values(variable list). (I am programming dialogs for non/occasional
users of Stata and am trying to insulate people form cryptic variable
names)  I have had no difficulty programming comboboxes with this type
of construct in other languages so I am surprised I can't seem to do
it here.

(II)
Another issue I have been unable to resolve is how to *put* a "quoted
string" onto the rstring.  As a silly example:

PROGRAM command
BEGIN
	put "di "
	put "Goodbye cruel world"
END

The quotes are stripped so the output command is -di Goodbye cruel
world- rather than -di "Goodbye cruel world"- and attempts at various
quote combinations and attempts to use separate puts with char(34) are
to no avail, nor is any use of escaped characters.

Thanks in advance for any help/insights provided.

--
David Elliott
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index