Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Constrained OLS

    Hi, is it possible that I can force my independent variables in regress to be positive and add up to 1?
    Code:
    clear *
    
    
    cls
    
    
    u "http://fmwww.bc.edu/repec/bocode/s/synth_smoking.dta", clear
    
    keep state year cigsale
    
    
    frame put state year cigsale, into(scmframe)
    
    cwf scmframe
    
    reshape wide cigsale, i(year) j(state)
    
    // California's ID is 3, so it goes first by convention
    order cigsale3, a(year)
    
    tsset year
    
    reg cigsale3 cigsale1-cigsale39 if year < 1989, nocons
    
    predict cf_Cali
    
    line cigsale3 cf_Cali year, xli(1989)
    
    br
    I want to illustrate the synthetic control method as simply being a from of constrained OLS, but I've never manually done this in Stata. Easily done in Python, but I was unsure if we could do it here. Precisely, I need for there to be 1: no constant, 2, all the betas should be greater than or = 0, and the sum of the coefficients must add up to 1. I know cnserg exists, but I've never used it and I was wondering if someone else has

  • #2
    Working with constraints is too difficult, but you'll find that they only work with linear constraints, no non-linear (including inequalities).

    Here's an example using a constraint on the sum of coefficients:

    Code:
    sysuse auto, clear
    
    reg mpg head trunk length
    
    constraint 1 _b[headroom] + _b[trunk] + _b[length] = 1
    cnsreg mpg head trunk length, constraint(1)
    You'll see there's no guarantee that all coefficients are constrained to be non-negative. To the best of my knowledge, SEM software is more naturally able to impose non-linear constraints of the type you're interested (MPlus is what I'm familiar with), but Stata's sem/gsem are both limited to the linear constraints (as I think are all of the usual estimation commands in Stata).

    Comment


    • #3
      Okay this makes sense! No wonder the real optimizations are done in Mata.

      Comment

      Working...
      X