Settings the master page for a SharePoint 2007 publishing website can be done out of the box using the UI or programmatically. For guidance on how to set the MasterPage programmatically, Mike Hodnick has a good post.
However, if you want to set the Master Page for an individual page or pages within a website, things get tricky.
The @Page directive exposes the MasterPageFile property, but the value is immediately overwritten in the Pre-Init event of the publishing pages base class (PublishingLayoutPage).
To resolve this, we will have to set the MasterPageFile through code. Andrew Connell provides a nice tutorial on how to create a code-behind class for a layout page.
Once you have created the code-behind class, override the OnPreInit event method and set the MasterPageFile property immediately after the base.OnPreInit(e) call.
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
// override the MasterPageFile which is set in the Pre-Init with our own.
MasterPageFile = "mymaster.master";
}