/*
	mi reshape

*!  VERSION 1.0.2  03jul2009

*/

VERSION 11.0

INCLUDE _std_large
DEFINE _dlght 310
INCLUDE header

HELP hlp1, view("help mi_reshape")
RESET res1

DIALOG main, label("mi reshape - Reshape mi data") /*
		*/ tabtitle("Main")
BEGIN
  RADIO    rb_long            _lft     _top _comb4_1        ., first	/*
		*/ label("Long format from wide")			/*
		*/ clickon("script main_all_on")			/*
		*/ option(long)
  BUTTON   bu_example      _lft4_4        @  _cwd4_1        .,		/*
		*/ label("Example...")					/*
		*/ push("script example")
  RADIO    rb_wide            _lft      _ss     _iwd        ., last 	/*
		*/ label("Wide format from long")			/*
		*/ clickon("script main_all_on")			/*
		*/ option(wide)
  TEXT     tx_var_i              @      _ls        @        .,		/*
		*/ label("ID variable(s) - the i() option:")
  VARLIST  vl_var_i              @      _ss        @        .,		/*
		*/option(i)						/*
		*/ label("ID variable(s)")
  GROUPBOX gb_j			 @	_ls	   _iwd	    _ht8,	///
	label("Subobservation identifier - the j() option")
  TEXT     tx_var_j              _indent  _ss      _cwd1    .,		/*
		*/ label("Variable:")
  DEFINE holdy @y
  VARNAME  vn_var_j              @        _ss    _vnwd      .,		/*
		*/ label("Variable")
  TEXT     tx_jvals              _lft2   holdy     _cwd3    .,		/*
	*/ label("Values: (optional)")
  EDIT     ed_jvals              @      _ss        @        .,		/*
		*/ label("Values")
  CHECKBOX ck_string          _ilft     _ls     _iwd        .,		/*
		*/ option(string)					/*
	*/ label("Allow the subobservation identifier to include strings")

  TEXT     tx_var              _lft     _xxls     _iwd      .,		/*
		*/ label("Base (stub) names of X_ij variables:")
  VARLIST  vl_var                @      _ss        @        .,		/*
		*/ label("Base (stub) names of X_ij variables")

  TEXT     tx_note               @      _ls        @        .,		/*
	*/ label("Note:  All other variables should be constant within ID.")
END

SCRIPT example
BEGIN
  view help reshape_example##|_new
END

SCRIPT main_all_on
BEGIN
	main.tx_var_i.enable
	main.vl_var_i.enable
	main.gb_j.enable
	main.tx_var_j.enable
	main.vn_var_j.enable
	main.tx_var.enable
	main.vl_var.enable
	main.tx_note.enable
	main.ck_string.enable
	main.tx_jvals.enable
	main.ed_jvals.enable
END

PROGRAM j_output
BEGIN
	varlist main.vn_var_j
	
	if main.ed_jvals {
		put " " main.ed_jvals
	}
END

PROGRAM command
BEGIN
	put "mi reshape "
	option radio (main rb_long rb_wide)
	if main.rb_long | main.rb_wide {
		varlist main.vl_var
		beginoptions
			optionarg main.vl_var_i
			put "j(" 
			put /program j_output
			put ")"
			option main.ck_string
		endoptions
	}
END

