Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: choice modelling
From
Maarten buis <[email protected]>
To
[email protected]
Subject
Re: st: choice modelling
Date
Sun, 20 Jun 2010 09:26:46 +0000 (GMT)
--- On Sat, 19/6/10, Tyler Frazier wrote:
> What is the best way to run a choice model in Stata -- for
> example a household location choice model. I have two datasets,
> one representing households and the other representing
> residential dwellings and would like to develop a choice model
> that a) randomly assigns certain households for a move from their
> existing location to a new location based on the households
> probability of moving (which I already have from survey results)
> b) matches a household to a new location based on the
> characteristics of both
I am guessing that you are trying to create what some would call an
agent based model, so you are not trying to estimate parameters, but
try to figure out how a set of "individuals" following a set of rules
(with or without estimated parameters) result in some aggregate
behaviour. Below is a silly example, but it can give you an idea how
you could approach such an example. I created the two datasets randomly
(primarily, because I don't have access to those. You can use real
datasets if you want) Then I selected those who moved in such a way
that those whose difference between price and inc is larger have a
larger probability to move. Then I matched those such that the
difference between price and inc is minimum (this is actually not
quite right, in this example I made a mistake, such that it is
possible that I select a "price" that is actually the inc of a
fellow mover. I leave it as an excercise to the reader to spot where
that mistake is, and how to solve it...)
*------------------------ begin example -----------------------
set seed 12345
tempfile hhold house
// "create" household file
drop _all
set obs 100
gen id = _n
gen inc = exp(rnormal())
gen price = exp( log(inc) + .5*rnormal())
save `hhold'
// "create" house file
drop _all
set obs 200
gen houseid = _n
gen price = exp(rnormal())
save `house'
// select those who move
use `hhold'
gen move = runiform() < invlogit(-1 + abs(price - inc))
count if move
local Nmove = r(N)
// find them a new house
// (difference between inc and price is minimum)
keep if move
drop price
rename inc price
append using `house'
sort price
replace price = cond(abs(price[_n-1] - price) < abs(price[_n+1]-price), ///
price[_n-1], price[_n+1])
keep if id < .
drop houseid
merge 1:1 id using `hhold'
count if _merge == 3
assert r(N) == `Nmove'
drop _merge move
*----------------------------- end example -------------------------------
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/