Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: coding for weighting factor variable -weight-

From   Steve Samuels <>
Subject   Re: st: coding for weighting factor variable -weight-
Date   Tue, 31 Jan 2012 17:37:58 -0500

I'm not sure that I understand your question completely,  but I think that you want a weighted average of variables from two observations to be put into a single observation.  If so, -collapse- provides a way.

*************CODE BEGINS*************
sysuse auto, clear
keep in 1/2 
drop make
gen part = _n // 
label define part 1 "West" 2 "East"
label values part part
list mpg weight length trunk part

gen myweight = 1.23 if part==1
replace myweight= 0.55 if part==2
collapse mpg weight length trunk [pw =myweight]
gen country ="Germany"
**************CODE ENDS**************

By the way, "STATA" is not correct spelling of the program we all use, but "Stata" is. See the end of the Statalist FAQ for the reason. 


On Jan 31, 2012, at 3:36 PM, David Cefskimal wrote:

Dear statlisters,

I create a variable "Germany" but when the whole country is taken as
the unit of analysis (rather than eastern and western states), a
design weight is necessary: weighting factor for Western Germany:
1,23; weighting factor for Eastern Germany: 0,55.

As the help weight command did not solve my problem, I would be v.
thankful if someone could tell me how to code that in STATA. Many
thanks, David
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index