Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: SUR on stacked data

From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: Re: SUR on stacked data
Date   Thu, 17 Apr 2003 21:32:20 -0500

----- Original Message -----
From: "Vimalanand S. Prabhu" <[email protected]>
To: <[email protected]>
Sent: Wednesday, April 16, 2003 11:01 PM
Subject: st: SUR on stacked data

> Dear Friends,
> I have data stacked into columns. I want to conduct a SUR on this data
> Y1 = f(x1)
> Y2= f(x2)
> where y1, x1 and y2, x2 are variables for different gender.
> Note that both Xs are not same (else SUR is algebriacally equivalent to
> OLS).
> Do you  know how to convert a stacked dataset into a formal where I can
> directly use "sureg" command for SUR model?
> Thanks,
> Prabhu


I believe the following little program will work.  It creates a series of
new variables for each group beginning at the same observation number as the
first group.


separate2 invest mvalue kstock, group(company)

and then
 sureg (invest1 mvalue1 kstock1) (invest2 mvalue2 kstock2) ....

I hope this helps,

-----start of separate2.ado-----
program separate2
version 8.0

syntax varlist, group(varname)

tempname Vals /*Pilfered from Nick Cox's -levels- */
 qui tab `group' , matrow(`Vals')
 local nvals = r(r) -1
 local sep " "
 forval i = 1 / `nvals' {
     local val = `Vals'[`i',1]
     if `i' < `nvals' local vals "`vals'`val'`sep'"
    else local vals "`vals'`val'"
local levels `"`vals'"'

qui sum `group'
local min = r(min)

foreach var of varlist `varlist' {
 local i = `min'
 local num = 0
 separate `var', by(`group')
 foreach x of local levels {
  qui sum `var'`i'
  local num = `num' + r(N)
  local i = `i' + 1
  replace `var'`i' = `var'`i'[_n+`num']


*   For searches and help try:

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